Don't Close Form If...

S

Sash

I want to build and event procedure in Close Form that says if field A is
null, don't close the form.

If IsNull(FieldA) then
MsgBox "Field A is Not Complete"
End If

But how do I then state, don't continue to close the form.
 
D

Douglas J. Steele

Check in the Unload event, not the Close event:

Private Sub Form_Unload(Cancel As Integer)

If IsNull(FieldA) then
MsgBox "Field A is Not Complete"
Cancel = True
End If

End Sub
 
F

fredg

I want to build and event procedure in Close Form that says if field A is
null, don't close the form.

If IsNull(FieldA) then
MsgBox "Field A is Not Complete"
End If

But how do I then state, don't continue to close the form.

Use the Form's Unload event for this:

Private Sub Form_Unload(Cancel As Integer)
If IsNull([ControlA]) Then
MsgBox "ControlA is not complete."
Me!ControlA.SetFocus
Cancel = True
End IF
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top