By the structure theorem of finite abelian groups, we have that an abelian group of order $n$ is a product:
$$G \cong \prod_{i = 1}^k \Bbb Z_{n_i}$$
such that $\prod\limits_{i=1}^k n_i = n$, and each $n_i = p_i^{e_i}$ is a power of a prime.
Therefore, the order of an element $g$ of $G$ can at most be $\operatorname{lcm}(n_1, \ldots, n_k)$, the least common multiple of the $n_i$ (in fact, this order will be attained by the element $(1,\ldots, 1)$ as one easily verifies).
Thus our question reduces to finding conditions on $n$ such that $\operatorname{lcm}(n_1,\ldots,n_k) = n$; equivalently, that all $n_i$ are coprime.
This can only be ensured when $n$ is squarefree; otherwise, there is a prime $p$ such that $p^2 \mid n$, and we have the group $\Bbb Z_p \times \Bbb Z_p \times \Bbb Z_{n'}$ with $n' = n/p^2$ in which no element has order $n$.
In conclusion, an abelian group $G$ has an element of order $n = |G|$ if $n$ is squarefree. For groups of non-squarefree order $n$, there may be such an element (e.g. in $\Bbb Z_n$ there is) but in some groups of order $n$ there won't be.
(In particular, it follows that all abelian groups of squarefree order $n$ are cyclic, i.e. isomorphic to $\Bbb Z_n$. Thus in some sense, there is "only one" such group.)