The code below alerts the user that some fields are blank.
It works until the last line!!!
How can I make it keep the form open an go to the first blank field, then
the second etc..(I'll be adding more)???
Private Sub Form_Close()
If (IsNull(Me.FirstName)) Or (IsNull(Me.LastName)) Then
If MsgBox("Do you want to Edit Member Information now?", vbQuestion &
vbYesNo, "Question") = vbYes Then
(Me.???) ???.SetFocus
fredg - 31 Jan 2008 17:31 GMT
> The code below alerts the user that some fields are blank.
> It works until the last line!!!
[quoted text clipped - 8 lines]
> vbYesNo, "Question") = vbYes Then
> (Me.???) ???.SetFocus
The Close event is too late in the Form closing series of events.
Use the Form's Unload event. You can Cancel the unloading and set
focus where ever you wish.
Private Sub Form_Unload(Cancel as Integer)
If IsNull(Me.FirstName) Or IsNull(Me.LastName) Then
If MsgBox("Do you want to Edit Member Information now?",
vbQuestion & vbYesNo, "Question") = vbYes Then
Cancel = True
Me.[FirstName].SetFocus
End If
End If
End Sub

Signature
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Klatuu - 31 Jan 2008 17:44 GMT
First, you need to move the code to the Form UnLoad event. The close event
is too late and can't be canceled. The form will just close.
Private Sub Form_UnLoad(Cancel As Integer)
Dim strCtl As String
Dim blnCancel As Boolean
If IsNull(Me.FirstName) Then
blnCancel = True
strCtl = "FirstName"
End If
If IsNull(Me.LastName) Then
blnCancel = True
strCtl = "LastName"
End If
If blnCancel Then
If MsgBox("Do you want to Edit Member Information now?", vbQuestion &
vbYesNo, "Question") = vbYes Then
Me.Controls(strCtl).SetFocus
Cancel = True
End If
End If
End Sub

Signature
Dave Hargis, Microsoft Access MVP
> The code below alerts the user that some fields are blank.
> It works until the last line!!!
[quoted text clipped - 8 lines]
> vbYesNo, "Question") = vbYes Then
> (Me.???) ???.SetFocus