We help IT Professionals succeed at work.

Pop up form

sannunzi
sannunzi used Ask the Experts™
on
I am creating a form to pop up when a user loses focus on a control.  I am populating the popup form text box with the number that they typed in the control and asking them to verify if the number is correct.  I am not using a message box because I want the number to be large so they can read it and verify that it is correct.

If the number is correct, I just have them click YES and it takes them back to the next control in the form.  If it is NO, I want to take them back to the control that they left (or lost focus) from.  I want to close the popup form and then set focus back on the other form's control.  I can get back to the form, but I can't get back to the control that I previously lost focus from.
This is what I have when the NO is clicked:

Docmd.close
Forms!ChecksandStops![PositionX].SetFocus

I get an error that it can't find the field PositionX.  I tried just setting focus to the form and then to the field, but that didn't work either.

Any ideas?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hamed NasrRetired IT Professional

Commented:
One idea:
Hamed NasrRetired IT Professional

Commented:
One idea.
Using a global variable to set when navigating between form and popup.

Check this sample database.
popThenSetFocus.accdb

Author

Commented:
I am using Access 2003.  Can you just post the code.  Can't open the sample
Retired IT Professional
Commented:
One idea.
Using a global variable to set when navigating between form and popup.

Check this sample database.
2003 format.

Good luck!
popThenSetFocus.mdb
If the form's visible property is set to false, you must set to true before setting focus.  Likewise, if the target control on the form is not enabled, it must be enabled before setting focus,

See this link for restrictions for using the  SetFocus method in VB.
          http://msdn.microsoft.com/en-us/library/aa221598(v=office.11).aspx

Note the following:
You can move the focus only to a visible control or form. A form and controls on a form aren't visible until the form's Load event has finished. Therefore, if you use the SetFocus method in a form's Load event to move the focus to that form, you must use the Repaint method before the SetFocus method.

You can't move the focus to a control if its Enabled property is set to False. You must set a control's Enabled property to True (–1) before you can move the focus to that control. You can, however, move the focus to a control if its Locked property is set to True.

If a form contains controls for which the Enabled property is set to True, you can't move the focus to the form itself. You can only move the focus to controls on the form. In this case, if you try to use SetFocus to move the focus to a form, the focus is set to the control on the form that last received the focus.