Required Field

  • Thread starter maxjake via AccessMonster.com
  • Start date
M

maxjake via AccessMonster.com

Hi All
Please Help.

I have a form that opens on click of a option group button. When the form
opens I require fields to be completed before the form can be closed.

Private Sub Form_Close()
If IsNull(Me.[Passed To]) Then
MsgBox "Who have the works been Passed To?", vbExclamation, "Invalid
Operation"

End If
End Sub

This code gives me the message that I want when I try to close the form BUT
then the form closes without the required field completed.
What code will stop the form from closing until the field is completed?????

Ta
Max
 
A

Allen Browne

Form_Close is too late. The data has already been written to the table when
this event fires.

Use the BeforeUpate event of the *form* (not control) to perform your test.
Cancel the event if the data is not right:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[Passed To]) Then
MsgBox "Who have the works been Passed To?", _
vbExclamation, "Invalid Operation"
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