Set Control back to current field (1 Viewer)

musclecarlover07

Registered User.
Local time
Today, 14:59
Joined
May 4, 2012
Messages
236
So I have a control called txtBranch. If the user does not put 1 of 4 options then a msgbox pops up and says that is an invalid option and then gives all the valid options. It then sets the value to blank. Then it moves to the next field. I do not want it to move to the next field. I want it to stay on txtBRanch till it has a correct value. I have tried DoCmd.GoToControl "txtBranch", Me.txtBranch.SetFocus on the OnExit, OnLostFocus, AfterUpdate events and it still continues to go to the next control how do I get it not to go to the next control?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:59
Joined
Aug 30, 2003
Messages
36,118
I would probably use the before update event of the form:

http://www.baldyweb.com/BeforeUpdate.htm

If you want to catch it as they leave the textbox, you might be able to use the lost focus event but you have to set focus twice if memory serves, first somewhere else then where you really want it.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:59
Joined
Aug 30, 2003
Messages
36,118
... just going to add that if you do use what pbaldy suggested, you should be able to set focus to the control in that event.

You mean as shown in the link? :rolleyes:
 

musclecarlover07

Registered User.
Local time
Today, 14:59
Joined
May 4, 2012
Messages
236
Awesome that worked almost perfectly. Now it wont set the field to blank. It still leaves the previous value in the field.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:59
Joined
Aug 30, 2003
Messages
36,118
Have you tried using Undo on the control?
 

musclecarlover07

Registered User.
Local time
Today, 14:59
Joined
May 4, 2012
Messages
236
THANK YOU. Works beautifully. I didn't even think of the undo action. i have only used that one other time. I never used the BeforeUpdate because I thought that it would validate before you typed. :/ but after looking more into what you said this is exactly what I needed for several other items. Again Thanks pbaldy
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:59
Joined
Aug 30, 2003
Messages
36,118
Happy to help! There are going to be a lot of muscle cars around here in the next week or two. Big car event in the area.
 

musclecarlover07

Registered User.
Local time
Today, 14:59
Joined
May 4, 2012
Messages
236
Ok so I'm back with a similar issue. The undo method worked with text boxes. But its not doing anything with combo boxes. Is there something different for this?
 

Users who are viewing this thread

Top Bottom