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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use VB command to open a report & @ same time export it to word doc

Status
Not open for further replies.

Triacona

Technical User
Jun 11, 2009
462
GB
Hi all,

I want the user to be able to click on a cmd button and the Access DB will generate a report and then export/open it in a word document
...like creating a template.

The code I have tried for the cmd button is as follows:

Code:
Private Sub Report_Click()
On Error GoTo Err_Report_Click

    Dim stDocName As String

    stDocName = "ChsRef"
    DoCmd.OpenReport stDocName, acPreview
    DoCmd.OutputTo acOutputReport, stDocName, doc, Template

Exit_Report_Click:
    Exit Sub

Err_Report_Click:
    MsgBox Err.Description
    Resume Exit_Report_Click
    
End Sub
It give me the error invalid or unqualified reference...


Any help would really be greatly appreciated
Kind regards
Triacona

Well, I solved it while writing this question.
the answer is
Code:
Private Sub Report_Click()
On Error GoTo Err_Report_Click

    Dim stDocName As String

    stDocName = "ChsRef"
    DoCmd.OpenReport stDocName, acPreview
    DoCmd.OutputTo acOutputReport, stDocName
    
    
Exit_Report_Click:
    Exit Sub

Err_Report_Click:
    MsgBox Err.Description
    Resume Exit_Report_Click
    
End Sub
Thanks for a great forum!! [bigsmile]
Kind regards
Triacona
Thought is often the best solution. [ponder]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top