Hi,
I have a pop-up form on which I need to perform a simple validation (verify that one item in an option group is checked, if another option button is checked) before the form is closed.
The form may or may not have changes on it before it is closed.
I first tried just putting my validation rule in the OnClick event of a "close" button (and disabled the "X" box close option). However, the validation rule would only trigger if the user clicked in a field (any field) on the form before clicking "close." I'm not sure why. I also tried moving the validation code to the OnClose and OnUnload events of the form. Same result both times. I also tried adding "Me.Requery" before running the validation in case that would help. No luck.
Obviously, the BeforeUpdate event will also not work because there may not be any changes to the form.
Is there an event that will be triggered no matter what, any time I close the form?
Just as a side note, I tried putting a break point in the code to make sure the validation was executing properly. Whenever a break point was present, the error box popped up (i.e., I could not duplicate the non-validating scenario with break points in the code).
Here is the code:
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
Me.Requery
If chkAdjust.Value = -1 Then
If optWho.Value = "" Then
MsgBox "You must select the responsible party.", vbExclamation, "Responsible Party"
Else
DoCmd.Close
End If
Else
DoCmd.Close
End if
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub
Thanks in advance,
Patricia
I have a pop-up form on which I need to perform a simple validation (verify that one item in an option group is checked, if another option button is checked) before the form is closed.
The form may or may not have changes on it before it is closed.
I first tried just putting my validation rule in the OnClick event of a "close" button (and disabled the "X" box close option). However, the validation rule would only trigger if the user clicked in a field (any field) on the form before clicking "close." I'm not sure why. I also tried moving the validation code to the OnClose and OnUnload events of the form. Same result both times. I also tried adding "Me.Requery" before running the validation in case that would help. No luck.
Obviously, the BeforeUpdate event will also not work because there may not be any changes to the form.
Is there an event that will be triggered no matter what, any time I close the form?
Just as a side note, I tried putting a break point in the code to make sure the validation was executing properly. Whenever a break point was present, the error box popped up (i.e., I could not duplicate the non-validating scenario with break points in the code).
Here is the code:
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
Me.Requery
If chkAdjust.Value = -1 Then
If optWho.Value = "" Then
MsgBox "You must select the responsible party.", vbExclamation, "Responsible Party"
Else
DoCmd.Close
End If
Else
DoCmd.Close
End if
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub
Thanks in advance,
Patricia