Cancel form close

  • Thread starter sheniece via AccessMonster.com
  • Start date
S

sheniece via AccessMonster.com

I have a modal window, I have 2 buttons a cancel button which disregards and
input and closes the window without saveing. The second button is a close
button which saves the information entered and then closes. I have some
input verification done n a field on the form, if this field is null i
popup a dialog box telling the user to select a value, so the value cannot be
blank or null, My problem is I canceled the close in the unload event if the
value does'nt meet the requirements but the cancel button is also canceling
the close. How do I ignore the check if cancel is pressed.



Private Sub cmdCancel_Click()
On Error Resume Next
Me.Undo
DoCmd.Close
End Sub


Private Sub Form_Unload(Cancel As Integer)
If Len(Me.cboContactDurationID & vbNullString) = 0 Then
MsgBox "Please select the contact duration.", vbOKOnly, "Incorrect
Entry."
Cancel = True
End If
End Sub
 
S

Stuart McCall

sheniece via AccessMonster.com said:
I have a modal window, I have 2 buttons a cancel button which disregards
and
input and closes the window without saveing. The second button is a close
button which saves the information entered and then closes. I have some
input verification done n a field on the form, if this field is null i
popup a dialog box telling the user to select a value, so the value cannot
be
blank or null, My problem is I canceled the close in the unload event if
the
value does'nt meet the requirements but the cancel button is also
canceling
the close. How do I ignore the check if cancel is pressed.



Private Sub cmdCancel_Click()
On Error Resume Next
Me.Undo
DoCmd.Close
End Sub


Private Sub Form_Unload(Cancel As Integer)
If Len(Me.cboContactDurationID & vbNullString) = 0 Then
MsgBox "Please select the contact duration.", vbOKOnly, "Incorrect
Entry."
Cancel = True
End If
End Sub

Forget using the unload event, because it will fire whichever way the form
is closed (as you found). Try putting the following code in your close
button's click event:

If Len(Me.cboContactDurationID & vbNullString) = 0 Then
MsgBox "Please select the contact duration.", vbOKOnly, "Incorrect
Entry."
Me.cboContactDurationID.SetFocus
Else
DoCmd.Close acForm, Me.Name
End If
 
S

sheniece via AccessMonster.com

ok. Thanks for the help. will do..

Stuart said:
I have a modal window, I have 2 buttons a cancel button which disregards
and
[quoted text clipped - 22 lines]
End If
End Sub

Forget using the unload event, because it will fire whichever way the form
is closed (as you found). Try putting the following code in your close
button's click event:

If Len(Me.cboContactDurationID & vbNullString) = 0 Then
MsgBox "Please select the contact duration.", vbOKOnly, "Incorrect
Entry."
Me.cboContactDurationID.SetFocus
Else
DoCmd.Close acForm, Me.Name
End If
 

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