Message Box Loses Focus

flemmo

Registered User.
Local time
Today, 15:03
Joined
Apr 26, 2006
Messages
69
If have the following code in a public module

Code:
Sub RunValidate()
If IsNull(Form_Form2.Description) = True Or Form_Form2.Description = "" Then
Form_Form2.Description.SetFocus
MsgBox ("Please enter a description for your item(s)")
End If
End Sub

Basically if the user moves out of form2 (presented as a subform of form1) then the focus is set back to "Description" in form2 with the message box alert.
The problem is the MsgBox is preventing the focus from working properly. The focus goes to "Description" but after clicking "OK" on the MsgBox, the focus goes to where the user clicked instead of staying in "Description".

Any ideas how I can resolve this?
Thanks
 
Move the MsgBox statement above the set focus statement:rolleyes:
 
I've tried that too. Same result.
 
Could you create a form that acts as a pseudo message box and then sets the focus to the correct location once it has been closed?
 
Ok, lets attach this from a different angle. first lets look at the tab index of the form and the controls.

Which controls normally receives the focus when the user presses the return or tab key on the description field.

Go to the on got focus property of this control and enter the folowing code

If Nz(Me.Description,"") = "" Then
Me.Description.SetFocus
End If
 
Which controls normally receives the focus when the user presses the return or tab key on the description field.

The problem is the user click away from the subform to the parent form with the mouse.
A pseudo message box might be the way forward. I'll give it a go.
Thanks for your help ;)
 
I sometimes deal with stuff like this by putting a label somewhere on the form, with the caption "you cannot leave this field blank", colouring the text red, then setting the visible property to false. Then the code looks like:

Sub RunValidate()
If IsNull(Form_Form2.Description) Or Form_Form2.Description = "" Then
Form_Form2.Description.SetFocus
Form_Form2.labelWarning.visible = True
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom