Let $M$ be a manifold of $m$--dimensional, and $M\subset \mathbb{R}^k$. Assume $m>n$. If every smooth function $f:M\longrightarrow \mathbb{R}^n$ has regular values that form an open subset of $\mathbb{R}^n$, is $M$ be a compact manifold?
I try to prove it as follow
Assume by contradiction that $M$ is not compact, then there is a open cover $\{V_\alpha\}_{\alpha\in \mathcal{A}}$ such that it doesn't have any finite subcover.
Since any manifold is paracompact, there exists a countable locally finite refinement $\{U_i\}_{i\in I}$ of $\{V_\alpha\}_{\alpha\in \mathcal{A}}$, in other word, it's a family of sets such that
(i) $I$ is countable.
(ii) $\{U_i\}_{i\in I}$ is an open cover of $M$ and locally finite.
(iii) For every $i\in I$, there exists $\alpha\in \mathcal{A}$ such that $U_i\subset V_{\alpha}$.
If $\{U_i\}_{i\in I}$ has a finite subcover, assume they are $\{i_1,i_2,\ldots,i_k\}$, then from (iii) property, we have $\{\alpha_{1},\ldots, \alpha_k\}\subset\mathcal{A}$ such that $U_{i_t} \subset V_{\alpha_t}$ for all $t=\overline{1,k}$, so clearly \begin{equation*} M\subseteq \bigcup_{t=1}^k U_{i_t} \subseteq \bigcup_{t=1}^k V_{\alpha_t} \end{equation*} So $\{V_{\alpha_t}\}_{t=1}^k$ is a finite subcover of $\{V_\alpha\}_{\alpha\in \mathcal{A}}$, it's a contradiction since $M$ is not compact. Hence $\{U_i\}_{i\in I}$ does not have any finite subcover.
we can take an open subcover $J\subset I$ such that \begin{equation*} U_j \nsubseteq \bigcup_{k\in J\backslash \{j\}} U_k \qquad\forall\; j\in J \end{equation*} Since $\{U_i\}_{i\in I}$ does not have any finite subcover, $J$ is not finite, we can assume $J = \mathbb{N}$.
Now we can choose a sequence $\{x_i\}_{i=1}^\infty$ such that \begin{equation*} x_i\in U_i\backslash \left(\bigcup_{j\in J\backslash \{i\}} U_j\right) \qquad\forall\; i\in \mathbb{N} \end{equation*}
Now, let $\{\varphi_i\}_{i=1}^\infty$ be the partition of unity subordinate to $\{U_i\}_{i=1}^\infty$. Then $x_i$ is the critical point for $\varphi_i$ for all $i\in \mathbb{N}$ since $\varphi_i(x_i) = 1$ for all $i\in \mathbb{N}$, by \begin{equation*} \sum_{j=1}^\infty \varphi_j(x_i) = 1 \end{equation*} and $x_i\notin U_j$ for all $i\neq j$, so $\varphi_j(x_i) = 0$ for all $j\neq i$. It's implies $\varphi_i(x_i) = 1$. So $x_i$ must be a critical point of $\varphi_i$ since $\varphi_i$ archives maximum at $x_i$.
Case $N=\mathbb{R}^n$, setting $\{r_i\}_{i=1}^\infty = \mathbb{Q}^n\cap [0,1]^n$, and define \begin{align*} f: M &\longrightarrow \mathbb{R}^n\\ x &\longrightarrow \sum_{i=1}^\infty r_i\varphi_i(x) \end{align*} Clearly $f$ is smooth, so by Sard's theorem, there exists a regular value $y\in \mathbb{R}^n$ of $f$. Note that $f(M)\subseteq [0,1]^n$, so $y\in [0,1]^n$. And clearly $f(x_i) = r_i$ for all $i\in \mathbb{N}$.
Now, I try to show that $r_i$ is a critical value of $f$ for all $i\in \mathbb{N}$. Or maybe try another function $f$ has this property. If I have this, I can complete this proof easily by the contradiction to the openness of set of regular values
This is indeed true for all $n\ge 1$ and what you have written can be converted to a proof: Use a partition of unity to construct a smooth function $g: M\to R^n$ whose set of critical values is unbounded in $R^n$. Now, compose $g$ with a diffeomorphism $h: R^n\to B^n\subset R^n$, where $B^n$ is the open unit n-ball. Then each point on the boundary of $B^n$ is a regular value of $f=h\circ g$ (since it is not a value!) but one of these points will be the limit of critical values. Hence, the set of regular values of such $f$ is not open.
For @Najib Idrissi: This argument breaks down for $n=0$ since $R^0=B^0$ and, hence, $B^0$ has empty boundary in $R^0$.