Link to home
Start Free TrialLog in
Avatar of sannunzi
sannunzi

asked on

Pop up form

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?
Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

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

Check this sample database.
popThenSetFocus.accdb
Avatar of sannunzi
sannunzi

ASKER

I am using Access 2003.  Can you just post the code.  Can't open the sample
ASKER CERTIFIED SOLUTION
Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.