Save Current Record in a Report to PDF

eicarril

New member
Local time
Yesterday, 19:57
Joined
Mar 31, 2011
Messages
5
Hello Everyone,

I have a form where I would like to click on a button and have it save a report but only of the current record. I would like to have it save under a name similar to a key being used in the database. This is what I currently have.

Private Sub CmdSendtoFile_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "Rate Confirmation"
strWhere = "[Load]=" & Me!Load
DoCmd.OpenReport strDocName, acPreview, , strWhere

End Sub
 
Hello Everyone,

I have a form where I would like to click on a button and have it save a report but only of the current record. I would like to have it save under a name similar to a key being used in the database. This is what I currently have.

Private Sub CmdSendtoFile_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "Rate Confirmation"
strWhere = "[Load]=" & Me!Load
DoCmd.OpenReport strDocName, acPreview, , strWhere

End Sub


Something like this might help!!!
Put this text (below) as last line, before "End Sub"

DoCmd.OutputTo acOutputReport, "Rate Confirmation", acFormatPDF, _
"C:\my document\Rate Confirmation"& load & ".PDF"
 
The top left field says (General) and the top right field says CmdSendtoFile_Click

Private Sub CmdSendtoFile_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "Rate Confirmation"
strWhere = "[Load]=" & Me!Load
DoCmd.OpenReport strDocName, acPreview, , strWhere

DoCmd.OutputTo acOutputReport, "Rate Confirmation", acFormatPDF, _
"C:\Users\Born2Gamble\Desktop" & Load & ".PDF"
End Sub

Private Sub Command720_Click()

End Sub

Nothing happens when I click the button though...I created a Text Box, then i went to Event, and clicked even procedure and have that on the screen, am I doing it wrong?

I named my form Rate Confirmation........ what does the stWhere= Load refer to ? ..i am trying to copy the names and name my files that to get this work, thank you
 
Last edited:
The slight flaw with OutputTo is that to give file a name you want when you are not doing it with Save As, you need to give it full save path including a file name, but if you ever need to move the location of your database to another folder you would also need to change the code accordingly. Here's a solution that saves them to Reports sub-folder inside your database root folder. Note that to use it you must create the 'Reports' folder yourself.

Code:
Private Sub cmdSaveAsPDF_Click()

On Error GoTo ErrorHandler

    Dim myCurrentDir As String
    Dim myReportOutput As String
    Dim myMessage As String

    myCurrentDir = CurrentProject.Path & "\"
    myReportDir = myCurrentDir & "Reports" & "\"
    myReportOutput = myReportDir & "Name you desire" & ".pdf"
       
    DoCmd.OutputTo acOutputReport, [Report].[Name], _ 
    acFormatPDF, myReportOutput, , , , acExportQualityPrint

    myMessage = "Report generated inside " & myReportDir
        MsgBox myMessage, vbInformation
    
Done:
    Exit Sub
    
ErrorHandler:
    MsgBox Error$
    Resume Done

End Sub
Hope it helps.
 
Last edited:
got it working but I want to save it as ID-CONFIRMATION......instead of confirmation-id..have tried it various ways but keep getting errors


Desktop\Confirmation-" & ID & ".PDF"
 
got it working but I want to save it as ID-CONFIRMATION......instead of confirmation-id..have tried it various ways but keep getting errors


Desktop\Confirmation-" & ID & ".PDF"
Also..

I have one working...
Private Sub cmdsavepdf_Click()
Me.Refresh
Dim strDocName As String
Dim strWhere As String
strDocName = "Rate Confirmation"
strWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPreview, , strWhere

DoCmd.OutputTo acOutputReport, "Rate Confirmation", acFormatPDF, _
"C:\Users\Born2Gamble\Desktop\Confirmation-" & ID & ".PDF"
End Sub

But this one doesnt work for some reason........its saying their is an error on the line below...yet its the same line that is working on the above code.
DoCmd.OpenReport strDocName, acPreview, , strWhere

Private Sub cmdSaveInvoicePdf_Click()
Me.Refresh
Dim strDocName As String
Dim strWhere As String
strDocName = "Invoice"
strWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPreview, , strWhere

DoCmd.OutputTo acOutputReport, "Invoice", acFormatPDF, _
"C:\Users\Born2Gamble\Desktop\Invoice-" & ID & ".PDF"
End Sub

Regards,
 
Instead of using ID field you must refer to text box, have a hidden textbox in your form or wherever and call it for example txtID and then in your code refer to it [ID]=" & txtID.

If you wanna use fields instead of textbox you have to use recordset. And instead of hard coding the file path I'd suggest you to use line below to get the current database file location because if you change the location of your things you have to change the code.

CurrentProject.Path & "\"
 

Users who are viewing this thread

Back
Top Bottom