First Consider a finite dimensional vector space like $\mathbb R$. Take for $x$ the origin.
An example of a bounded subset for which distance is not attained below:
$A = (1,2]$
If $A$ is compact, then the distance is always attained. For the proof consider a sequence $(x_n)$ such that $d(x_n ,A) \to d(x,A)$ and extract a converging sub-sequence.
If $A$ is closed, then the distance is also always attained. For the proof, consider a point $a \in A$. Then $\overline A = \{y \in A \colon d(x,y) \le d(x,a)\}$ is compact and you can use point above.
Second. Case of an infinite dimensional vector space.
In that case, the distance may not be attained even if $A$ is closed. Look here for a counterexample.