Error While Running a report

khwaja

Registered User.
Local time
Tomorrow, 07:49
Joined
Jun 13, 2003
Messages
254
I have a command buton which allows users to clik and run a report for the matching record and print it. It works well if they proceed to print. But if they dismiss the print dialogue box, they get following message.

The expression On Click you entered as the event property setting: the runcommand action was cancelled

Could some please help me remove this error. It is appearing in the mde version of the db.
 
what kind of a message box is it? a form? or an actual message box that access has? if it's an on click, it's probably a form that you created.

what do you mean by DISMISS? close the form? push the cancel button instead of the "OK" button?

there may be different portions of your code conflicting with each other. post the code.
 
Thanks. The message appears as a system generated message box access has. So the routine is that I have a command button which I click to open a report matching the project ID. At the same time, print dialogue box also opens up for user to print the report. At this point if user prints, there is no issue. The report then closes. But if user chooses to cancel the print dialogue box, then I get the said error. I am using following code in the on click event of the button.

Private Sub CommandDV_Click()
On Error Resume Next
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptDVConstruction"

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
stLinkCriteria = "[ProjectID]=" & Me![ProjectID]
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
DoEvents
Do While Not CurrentProject.AllReports(stDocName).IsLoaded
DoEvents
Loop
DoCmd.SelectObject acReport, stDocName ' < be sure that the report has the focus before printing
DoCmd.RunCommand acCmdPrint
DoEvents
DoCmd.Close acReport, stDocName

Exit_CommandDV_Click:
Exit Sub

Err_CommandDV_Click:
'MsgBox err.Description
'Resume Exit_CommandCommandDV_Click
On Error GoTo 0
End Sub
 
i can't really see how the cancelling the print command gives you the error message, but the thing i would do is pop up a custom message box (one that you design as a form) and ask the user if they want to print the report. then, if they say yes, open the report in normal view and it will print automatically, as it is programmed by access that way. and if they say no, open it in preview mode, where it is not automatically set to print.

that would be a good alternative to what you're trying now. i am not very fond of runcommands, but they work for a lot of people.
 
DoMenuItem has been obsolete for years, use the RunCommand method instead. Also look up the actual ErrorNumber and trap it such as
If Err = 2501 Then
 

Users who are viewing this thread

Back
Top Bottom