K
kagard
Greetings:
I've set up all my forms to check for data in their respective
controls. I've also provided a command button on each form to close
the form. I have a global variable call
The close button has this code behind it:
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
This triggers the form's before update event, which I was hoping would
stop the close process, but it doesn't.:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not FormComplete(Forms!frmCOs) Then
FormReady = False
Cancel = True
End If
End Sub
FormComplete is a function that returns TRUE if the form is complete
and FALSE if it is incomplete. Since that didn't work, I searched this
group and found mention of the form's Unload event. I tried to keep
the form from closing using the following code:
Private Sub Form_Unload(Cancel As Integer)
Dim CloseAnyway As Boolean
If Not FormReady Then
CloseAnyway = MsgBox("You are closing this form with
incomplete information." _
& vbCrLf & "If you close this form, the data you've
entered will be disgarded." _
& vbCrLf & "Do you want to close the form anyway?",
vbYesNo, "Warning")
If CloseAnyway = vbNo Then DoCmd.CancelEvent
End If
End Sub
I used DoCmd.CancelEvent here because Cancel=True did nothing to stop
the form from closing. (Neither did this method.) Can anyone tell me
what I'm doing wrong? Thanks for your help.
Keith
I've set up all my forms to check for data in their respective
controls. I've also provided a command button on each form to close
the form. I have a global variable call
The close button has this code behind it:
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
This triggers the form's before update event, which I was hoping would
stop the close process, but it doesn't.:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not FormComplete(Forms!frmCOs) Then
FormReady = False
Cancel = True
End If
End Sub
FormComplete is a function that returns TRUE if the form is complete
and FALSE if it is incomplete. Since that didn't work, I searched this
group and found mention of the form's Unload event. I tried to keep
the form from closing using the following code:
Private Sub Form_Unload(Cancel As Integer)
Dim CloseAnyway As Boolean
If Not FormReady Then
CloseAnyway = MsgBox("You are closing this form with
incomplete information." _
& vbCrLf & "If you close this form, the data you've
entered will be disgarded." _
& vbCrLf & "Do you want to close the form anyway?",
vbYesNo, "Warning")
If CloseAnyway = vbNo Then DoCmd.CancelEvent
End If
End Sub
I used DoCmd.CancelEvent here because Cancel=True did nothing to stop
the form from closing. (Neither did this method.) Can anyone tell me
what I'm doing wrong? Thanks for your help.
Keith