Run-time error 2501 (1 Viewer)

mCool

New member
Local time
Today, 20:12
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
 

RuralGuy

AWF VIP
Local time
Today, 13:12
Joined
Jul 2, 2005
Messages
13,825
How about just testing for the value before running the Report?
 

mCool

New member
Local time
Today, 20:12
Joined
Nov 9, 2010
Messages
8
All sorted ! thanks a lot RuralGuy!
 

Users who are viewing this thread

Top Bottom