Docmd.Runcommand acCmdPrint

D

Dale Fye

Hey, guys,

I have a couple of custom menus, one on a form that hides the form and opens
a report in preview mode that only contains the record currently displayed
on the form (this code works great). I then created another shortcut menu,
this one for the report, to either print or close the report.
Unfortunately, the code for printing the report is not working as
anticipated. Instead of printing the report, it is printing the form (all
128 records). When I look at rpt.pages, it has the right number of pages,
but the runcommand is actually printing the form that is hidden rather than
the report. Any ideas how to get it to print the open report rather than
the form?

Public Function fnPrintReport()

Dim rpt As Report
Dim strMsg As String
Dim intResponse As Integer, bPrint As Boolean

On Error GoTo fnPrintReportError

Set rpt = Screen.ActiveReport

bPrint = True

If rpt.Pages > 10 Then
strMsg = "This report contains " & rpt.Pages & " pages! " _
& vbCrLf & vbCrLf _
& "Print this report anyway?"
intResponse = MsgBox(strMsg, vbOKCancel, "Excessive pages")
If intResponse = vbCancel Then bPrint = False
End If

If bPrint Then
On Error Resume Next
With rpt
Application.RunCommand acCmdPrint
On Error GoTo fnPrintReportError
End With
End If

Set rpt = Nothing
DoCmd.Close acReport, Screen.ActiveReport.Name
Exit Function

fnPrintReportError:
MsgBox Err.Number & vbCrLf & Err.Description, vbExclamation + vbOKOnly,
"Error in fnPrintReport"

End Function
 
F

FerdieB

I have the same issue: I open a report ("Rstatement") with the following
command behind a button on my form:
stDocName = "Rstatement"
DoCmd.OpenReport stDocName, acViewReport, , , acDialog

In the report displayed, a added a button to display only on screen. In the
OnClick event, I inserted the statements:

DoCmd.SelectObject acReport, "Rstatement"
DoCmd.RunCommand acCmdPrint

Also, the calling form is printed in stead of the report.

Pls help!!!
 
D

Dale Fye

Ferdie,

I don't remember how I got around this 2 years ago when I posted this. I'd
recommend posting a new message to the newsgroup, as this one is not likely
to be seen by many people, since the original email was so old.
--

Dale

email address is invalid
Please reply to newsgroup only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top