Return to same Text Box Command in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with several text boxes. In the On Change property of the
first I have some VBA code that tests for a value. If the value doesn't meet
the criteria, I use a message box with an OK to tell them to enter a correct
value. The focus moves to the next box on the tab list. I would like the
focus to go back to the first box. I have tried a setfocus.Text0 type
command but it still goes to the next box. What is the proper command to use
in the VBA to put the cursor back in the first box after displaying the
message? Thanks for your help.
 
Use the BeforeUpdate event of the textbox. If the value isn't valid, set the
Cancel variable to True in your code. That will cancel the focus change.
 
If its in the OnChange [EVENT], Me!ControlName.SetFocus should send the
focus back to it.
 
That does work - Thank you. I also tried it in the AfterUpdate event but it
doesn't work there. Why? What would work?

David C. Holley said:
If its in the OnChange [EVENT], Me!ControlName.SetFocus should send the
focus back to it.
I have a form with several text boxes. In the On Change property of the
first I have some VBA code that tests for a value. If the value doesn't meet
the criteria, I use a message box with an OK to tell them to enter a correct
value. The focus moves to the next box on the tab list. I would like the
focus to go back to the first box. I have tried a setfocus.Text0 type
command but it still goes to the next box. What is the proper command to use
in the VBA to put the cursor back in the first box after displaying the
message? Thanks for your help.
 
DoCmd.Requery solves the problem.

vtj said:
That does work - Thank you. I also tried it in the AfterUpdate event but it
doesn't work there. Why? What would work?

David C. Holley said:
If its in the OnChange [EVENT], Me!ControlName.SetFocus should send the
focus back to it.
I have a form with several text boxes. In the On Change property of the
first I have some VBA code that tests for a value. If the value doesn't meet
the criteria, I use a message box with an OK to tell them to enter a correct
value. The focus moves to the next box on the tab list. I would like the
focus to go back to the first box. I have tried a setfocus.Text0 type
command but it still goes to the next box. What is the proper command to use
in the VBA to put the cursor back in the first box after displaying the
message? Thanks for your help.
 
Back
Top