Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print a report from a form

Status
Not open for further replies.

Kysteratwork

Technical User
Jan 3, 2005
45
LU
Hi all,

I would like to print a report upon clicking button in a form.

The code I have so far is:
Code:
Private Sub PrintReport_Click()
On Error GoTo Err_PrintReport_Click

    Dim stDocName As String
    Dim MyReport As Report

    stDocName = "RptMeetings2005"
    Set MyReport = Report!RptMeetings2005
    DoCmd.SelectObject acReport, stDocName, True
    DoCmd.PrintOut
    DoCmd.SelectObject acReport, MyReport.Name, False

Exit_PrintReport_Click:
    Exit Sub

Err_PrintReport_Click:
    MsgBox Err.Description
    Resume Exit_PrintReport_Click
    
End Sub

But I am stuck at this point: Set MyReport = Report!RptMeetings2005, which clearly is wrong what I did.

Can you help me?

Kysteratwork
 
You could create commadn button through the wizard!!
OK here is it...
Code:
[COLOR=blue]Private Sub cmdPrintReport_Click()
On Error GoTo Err_cmdPrintReport_Click
    Dim stDocName As String
    stDocName = "RptMeetings2005"
    DoCmd.OpenReport stDocName, acNormal
Exit_cmdPrintReport_Click:
    Exit Sub
Err_cmdPrintReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdPrintReport_Click    
End Sub
[/color]
BTW the code DoCmd.PrintOut will print current form not report or any other object



Zameer Abdulla
[sub]Jack of Visual Basic Programming, Master in Dining & Sleeping[/sub]
Visit Me
 
Of course. I was trying to change the code from the Print Form wizzard.

Thank you

Kysteratwork
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top