There has been a bit of discussion regarding the following --
A text field on my main form must be tested that it has not been left blank. If it was, then a msgbox must be displayed notifying this fact, and returning the focus to this control. Here is my solution.
On my main form is a subform. As soon as the tab order moves my cursor into the subform, the main Form is tested for its completion - the Form BeforeUpdate function in the Form Properties.
I do not test at the control's BeforeUpdate level because once you loose focus of your text field it is difficult to get the cursor to backup to the field in question.
Here is my code - -
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.Owner & vbNullString) = 0 Then
MsgBox "You must enter the owner's name.", vbCritical, "Missing Owner's name!"
Cancel = True
Me.Owner.SetFocus
End If
End Sub
This is not a complex code solution but the problem that posters are having seems to be getting the focus back onto the offending control.
A text field on my main form must be tested that it has not been left blank. If it was, then a msgbox must be displayed notifying this fact, and returning the focus to this control. Here is my solution.
On my main form is a subform. As soon as the tab order moves my cursor into the subform, the main Form is tested for its completion - the Form BeforeUpdate function in the Form Properties.
I do not test at the control's BeforeUpdate level because once you loose focus of your text field it is difficult to get the cursor to backup to the field in question.
Here is my code - -
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.Owner & vbNullString) = 0 Then
MsgBox "You must enter the owner's name.", vbCritical, "Missing Owner's name!"
Cancel = True
Me.Owner.SetFocus
End If
End Sub
This is not a complex code solution but the problem that posters are having seems to be getting the focus back onto the offending control.