close button

laurat

Registered User.
Local time
Today, 22:10
Joined
Mar 21, 2002
Messages
120
I have placed code on the After_Update event of a form to check if a field named Quantity has been left null.

If IsNull(Me.Quantity) Then
MsgBox "You must enter a Quantity, it is a required field."
DoCmd.GoToControl "Quantity"
Cancel = True
End If

If the user presses the close button in the upper right hand corner of the form, It gives the message that quantity was left null, however, the form still closes. Is there a way I can prevent this from happening. I thought the Cancel=True would cause the form to remain open, however, it does not. Any suggestions??

Note: The code is also on a command button I created to close the form. I know that I can take the close button off of the upper right hand corner of the form in the form properties, however the button is still there unless the form is not maximized. Users would like all forms in the database to be maximized so they can see all data on the form.
 
Add an else to your If statement...

If IsNull(Me.Quantity) Then
MsgBox "You must enter a Quantity, it is a required field."
DoCmd.GoToControl "Quantity"
Cancel = True
Else
Exit Sub
'or
'End
End If
 
Unfortunately that did not work, the form still closed. Thank you for the suggestion. Are there any other suggestions?????
 

Users who are viewing this thread

Back
Top Bottom