Run-time error 2501

mCool

New member
Local time
Today, 16:27
Joined
Nov 9, 2010
Messages
8
Hi guys

I have implemented this code into a button on my form to invoke the action of print preview of a report based on an ID query. It works fine when the user inputs an ID into the field. But when the user clicks on the cancel button or the X button, a runtime error happens.

The error is "Run-time error '2501' : The OpenReport action was cancelled."

Is there something I could implement onto my code in addition to ignore this message ? It is just a precaution if the user accidentally clicks on the button and wishes to exit without entering the ID.

The code for the OpenReport is as follow :-
Code:
Private Sub btnARS_Click()
    strStudentID = "[StudentID]= '" & Me.[StudentID] & "'"
    DoCmd.OpenReport "AdviceRecordSheet1011", acViewPreview, strStudentID
    Me.ARSPrinted = True
End Sub
 
How about just testing for the value before running the Report?
 
All sorted ! thanks a lot RuralGuy!
 

Users who are viewing this thread

Back
Top Bottom