G
George Atkins
Acc2007. I have a form with several fields, one which is required. It is a
dropdown. I use a command button to close the form. I want the form to remain
open if - and only if - the record is edited and the dropdown field is not
filled in. But, if the user merely opens and closes the form without editing,
nothing should happen, even if the field is still blank.
I put the following code into the form's BeforeUpdate event:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Referral_Source = "" Then
MsgBox "You must select a referral source!", vbCritical +
vbDefaultButton1, "Missing Data"
Me.Referral_Source.SetFocus
DoCmd.CancelEvent
Else
Cancel = False
End If
End Sub
This much works, but the form still closes. What do I need to do to cancel
the close event, whether it occurs from the command button or the X?
dropdown. I use a command button to close the form. I want the form to remain
open if - and only if - the record is edited and the dropdown field is not
filled in. But, if the user merely opens and closes the form without editing,
nothing should happen, even if the field is still blank.
I put the following code into the form's BeforeUpdate event:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Referral_Source = "" Then
MsgBox "You must select a referral source!", vbCritical +
vbDefaultButton1, "Missing Data"
Me.Referral_Source.SetFocus
DoCmd.CancelEvent
Else
Cancel = False
End If
End Sub
This much works, but the form still closes. What do I need to do to cancel
the close event, whether it occurs from the command button or the X?