N
night_writer
I hope someone can help me. I've found two different solutions in
various newsgroups, but neither seems to work.
Upon exiting a form, I want to check that one and only of the
underlying records has a yes/no field set to -1. If that condition is
not met, I provide an appropriate error message and cancel the closing
of the form, so the user can fix the problem. My problem is that in
addition to my message, access adds a message that says: "You
cancelled the previous operation."
I have tried using DoCmd.SetWarnings before and after the cancel event
like this:
DoCmd.SetWarnings False
DoCmd.CancelEvent
DoCmd.SetWarnings True
It doesn't appear to have any effect. Then I found a posting that said
this was the result of error 2501, so I added a trap for that to the
OnError section, but that seems to have no effect either, including
the fact that I don't get any error number at all on the message box
that says "You cancelled the previous operation." So maybe this isn't
actually an error message? Anyway, my code is as below. I hope someone
can hope me remove the annoying extra message.
~~~~~~~~~
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Err_Form_Unload
Dim intDefaults As Integer
intDefaults = DCount("[strCompanyAbbrev]", "tlkpCompany", "[ynDefault]
= -1")
If intDefaults = 0 Then
MsgBox "You must select one company as the default."
DoCmd.CancelEvent
ElseIf intDefaults > 1 Then
MsgBox "There can be only one default company."
DoCmd.CancelEvent
End If
Exit_Form_Unload:
Exit Sub
Err_Form_Unload:
If Err.Number <> 2501 Then
MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
End If
Resume Exit_Form_Unload
End Sub
~~~~~~~~~~~~~~
Thank you for your assistance!
Alice
various newsgroups, but neither seems to work.
Upon exiting a form, I want to check that one and only of the
underlying records has a yes/no field set to -1. If that condition is
not met, I provide an appropriate error message and cancel the closing
of the form, so the user can fix the problem. My problem is that in
addition to my message, access adds a message that says: "You
cancelled the previous operation."
I have tried using DoCmd.SetWarnings before and after the cancel event
like this:
DoCmd.SetWarnings False
DoCmd.CancelEvent
DoCmd.SetWarnings True
It doesn't appear to have any effect. Then I found a posting that said
this was the result of error 2501, so I added a trap for that to the
OnError section, but that seems to have no effect either, including
the fact that I don't get any error number at all on the message box
that says "You cancelled the previous operation." So maybe this isn't
actually an error message? Anyway, my code is as below. I hope someone
can hope me remove the annoying extra message.
~~~~~~~~~
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Err_Form_Unload
Dim intDefaults As Integer
intDefaults = DCount("[strCompanyAbbrev]", "tlkpCompany", "[ynDefault]
= -1")
If intDefaults = 0 Then
MsgBox "You must select one company as the default."
DoCmd.CancelEvent
ElseIf intDefaults > 1 Then
MsgBox "There can be only one default company."
DoCmd.CancelEvent
End If
Exit_Form_Unload:
Exit Sub
Err_Form_Unload:
If Err.Number <> 2501 Then
MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
End If
Resume Exit_Form_Unload
End Sub
~~~~~~~~~~~~~~
Thank you for your assistance!
Alice