Error trapping 2501 problem

D

Dic_nutana

Dear all can anyone help please?
I'm having trouble trapping error 2501.
I'm using access 2003 (in 2000 mode) and I'm trying to trap the error when
opening a form with no data, here's my code:

Private Sub Form_Open(Cancel As Integer)
On Error GoTo ErrHandler

If Me.Recordset.RecordCount = 0 Then

MsgBox "Sorry there are no records" & vbCrLf & vbCrLf & _
"to display for this selection.", vbInformation + vbOKOnly, _
" No Records"

Cancel = True

End If
Open_exit:
Exit Sub

ErrHandler:
If Err.Number = 2501 Then
Resume Open_exit
Else
MsgBox Err.Number & " - " & Err.Description
Resume Open_exit
End If

End Sub

I get my custom message OK but then I still get the system message . What
have I done wrong? I'm sure this should work but I'm not sure where I have
gone wrong!
Many thanks in advance
Regards Richard
 
J

John Spencer

You are trapping for the error in the wrong place.

You should trap for the 2501 error in the code that is opening the form.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
D

Dic_nutana

Many many thanks I think I'm having a bad brain day! Thats it Ok

Regards
Richard
 

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