Error trapping 2501 problem

  • Thread starter Thread starter Dic_nutana
  • Start date Start date
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
 
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
 
Back
Top