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!

Output to PDF 1

Status
Not open for further replies.

crisis2007

Technical User
Apr 2, 2007
114
US
I have the following code on a button. I cannot figure out why I get a Type Mismatch error message when I try it. Can anyone see what is wrong with what I have here? I am just trying to save a report to PDF in the specified file. Eventually I am going to want it to take textbox values from the report as the name of the PDF when it is saved. But I cannot get this to even work.

Private Sub Command187_Click()
On Error GoTo Err_Command187_Click

Dim stDocName As String
TheFile = "C:\Documents and Settings\jdoe\Desktop\ActivityPDF\"
stDocName = "R_MasterWatch"

DoCmd.OpenReport stDocName, acPreview
DoCmd.OutputTo acFormatPDF, stDocName, TheFile, False, ""
TheMessage = "Report has been save to " & TheFile
Beep
MsgBox TheMessage, vbInformation, "Report Saved"

Exit_Command187_Click:
Exit Sub

Err_Command187_Click:
MsgBox Err.Description
Resume Exit_Command187_Click

End Sub
 
Try using this

DoCmd.OutputTo acOutputReport, strDocName, "PDFFormat(*.pdf)", TheFile & strDocName & ".pdf", False, "", 0, acExportQualityPrint


PaulF
 
Thanks for helping! I tried PaulF's code but receive the following message: "The Object Type argument for the action or method is blank or invalid." I do not know what that actually means - and not sure what is causing it.

As for dhookom's question - yes, it does compile but no, I do not have Option Explicit in the header. And I do not know which line causes the error as it only shows the type mismatch message box and does not revert to the code window and the code line causing the error.


 
The General Declarations section of every module should contain at least
Code:
Option Compare Database
Option Explicit
Try get rid of a "" where there should be a true/false
Code:
Private Sub Command187_Click()
On Error GoTo Err_Command187_Click

    Dim stDocName As String
    TheFile = "C:\Documents and Settings\jdoe\Desktop\ActivityPDF\"
    stDocName = "R_MasterWatch"
    
    DoCmd.OpenReport stDocName, acPreview
    DoCmd.OutputTo acFormatPDF, stDocName, TheFile, False
    TheMessage = "Report has been save to " & TheFile
    Beep
    MsgBox TheMessage, vbInformation, "Report Saved"

Exit_Command187_Click:
    Exit Sub

Err_Command187_Click:
    MsgBox Err.Description
    Resume Exit_Command187_Click

End Sub

Duane
Hook'D on Access
MS Access MVP
 
Thanks dhookum - I tried what you suggested but I am still getting the same "Type Mismatch" message. The code seems to stop after the print preview of the report at which time the error message appears (I can see the preview of the report behind the message). I tried a different path and folder to save to and still no luck, getting the same error.
 
I made a typo.. I used strDocName instead of stDocName, change that and it should work.

PaulF
 
Thanks again for helping. I fixed the part you mentioned PaulF. It appears that it is saving as the message that flashes very quickly says: Printing
Now outputting R_MasterWatch
'R_MasterWatch" to the file 'R_MasterWatch.pdf'

Unfortunately, it for some reason is not ending up in the folder where I wanted it to go. I have no idea where it is going. I even placed a msg box at the end to pop up when the code is finished. The message box pops up as if it should all be working properly.

And dhookom - I did as you mentioned after researching the importance of Option Explicit (I am self-taught and constantly learning even fundamental things). However it seems like the code should work. It still comes up with the "type mismatch" message. The best I can tell is that the code is stopping at this line:
DoCmd.OutputTo acFormatPDF, stDocName, TheFile, False
 
Try unscramble your code like:
Code:
    Dim stDocName As String
    Dim TheFile As String
    Dim theMessage As String
    TheFile = "C:\Documents and Settings\jdoe\Desktop\ActivityPDF\"
    stDocName = "R_MasterWatch"
    DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, TheFile & stDocName & ".pdf", False
    theMessage = "Report has been save to " & TheFile
    Beep
    MsgBox theMessage, vbInformation, "Report Saved"

Duane
Hook'D on Access
MS Access MVP
 
That did it - it works perfectly now! Thank you very much - I appreciate your patience with my very limited knowledge. I see what you did and it makes sense to me now. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top