Voting in primary elections

I may be moving to another state in the near future. While the state I presently live in and the state to which I may move have both held primary elections, the potential move does bring to mind a question:

What is a person to do about voting if they move from a state that has not yet held primary elections to a state which has? For the hypothetical argument, let’s take this to extremes: what if a person moves from Montana (their primaries are 6/8 per this site) to Iowa (caucuses held on 1/19) in mid-March. It’s too late to vote in Iowa, but Montana’s elections are almost 3 months away.

Can the person vote in the Montana primaries via absentee ballot? If they officially change their address to an Iowa residence (new driver’s license, register to vote in the next election–Novemeber general election, etc.) would that negate the Montana absentee ballot. Or is there a special exemption to allow them to vote? Does such a special exception limit them to the presidential election only (since they shouldn’t have a say in either Montana’s federal or state congress members)?

Another question:

If I do move, it will be well before the general election, so I would have time to register as a resident. But what does a person do if they move to another state only a few days before an election? Again, is there a special exemption to allow them to vote by absentee in the location from which they move? And, again, is it restricted to offices that are applicable to the new location (president only if the move is state-to-state)?

Here in Minnesota, the legal residency requirement for voting is that you reside at that address for 20 days prior to the election. (And you can register at the polls.)
If you moved less than 20 days before the election, I would think you could still vote by absentee in your prior state. (Presumably, you should not vote in both states. But I don’t know how they would catch you if you did.)

So if you lived in Montana & voted in the June Primary Election, then moved to Minnesota during the summer, I guess you could legally vote again in the Minnesota Primary in September.

Thanks for the info t-bonham. Minnesota is the state to which I may be moving. If I do move, it would be late spring/early summer, so I suspect I would be registered well before the general election. But if I get lazy, it’s nice to know I can register at the polls.