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 :-
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