Error handling with Apply Filter event

F

Fred Boer

Hello!

I like to use the shortcut menu item "Filter For:" when I am browsing or
editing data. I have been trying unsuccessfully, however, to manage certain
error messages. I wish to either forestall these messages and/or use custom
error messages. In particular, I am trying to cope with 3021 "No current
record", 3464 "Type mismatch", and 2001 "Cancelled previous operation..).

Problem 1:

The problem began with the following code, which I put in the ApplyFilter
event:

If DCount("*", Me.RecordSource, Me.Filter) = 0 Then
MsgBox "There are no records which match this criteria.", vbInformation +
vbOKOnly, "W. Ross Macdonald School"
Cancel = True
End If

Ok.. My form has textboxes and comboboxes. With textboxes, if I enter data
which is of the correct datatype, but won't return any records, this code
works correctly. BUT, with comboboxes, I see the 2001 "Cancelled" error
message. When I click on "OK", the form is displayed with the filter
correctly applied.

So.. where is the "Cancelled" error coming from? I tried setting break
points in the ApplyFilter event. The code stops on the "If DCount" line, and
then, after pressing F5, up pops the "Cancelled" error message. I can't
figure out where this comes from! How can I trace this?

Problem 2:

Ok, so putting that one aside, I also want to trap for no data or type
mismatch errors. But I can't seem to get my errorhandling to trap the error.
I put the following code in the form Error event and it doesn't fire. I see
the Access error, but not my messagebox.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If err.Number = 3464 Then
MsgBox "blah blah"
Cancel = True
Response = acDataErrContinue
End If

End Sub


I tried it like this, too, and no messagebox:


Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)

On Error GoTo Errorhandler

If DCount("*", Me.RecordSource, Me.Filter) = 0 Then
MsgBox "There are no records which match this criteria.", vbInformation
+ vbOKOnly, "W. Ross Macdonald School"
Cancel = True
End If

ExitPoint:
Exit Sub

Errorhandler:
If err.Number = 3464 Then
MsgBox "blah blah"
Cancel = True

Else

fncWRMSErrMsg err.Number, err.Description
Resume ExitPoint
End If

End Sub


Thanks for any suggestions!
Fred Boer
 

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