I want to save the report as invidual PDF using Query paramerts (1 Viewer)

rehanemis

Registered User.
Local time
Today, 11:53
Joined
Apr 7, 2014
Messages
195
Hi,
I am trying to save the reports on disk using Query records. the program works well for all records but giving error when I type parameter in query design.
The below code working well for all records in query but not working when I set parameter in a query design for a field which linked with a form field.

The error" Too few parameters, expected 1"
any solution? or alternative?

Code:
Private Sub Command14_Click()
Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim MyFileName As String
    Dim mypath As String
    Dim temp As String


    mypath = "C:\gw\"

    Set db = CurrentDb()

    Set rs = db.OpenRecordset("SELECT distinct [PayrollFor] FROM [qry_SalarySlipIndividual]", dbOpenSnapshot)

    Do While Not rs.EOF

        temp = rs("PayrollFor")
        MyFileName = rs("PayrollFor") & ".PDF"

        DoCmd.OpenReport "rpt_SalarySlipIndividual", acViewReport, , "[PayrollFor]='" & temp & "'"
        DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName
        DoCmd.Close acReport, "rpt_SalarySlipIndividual"
        DoEvents

        rs.MoveNext
    Loop


    rs.Close
    Set rs = Nothing
    Set db = Nothing
End Sub
 

rehanemis

Registered User.
Local time
Today, 11:53
Joined
Apr 7, 2014
Messages
195
I want to be specific as I don't got solution from the link. So Can you please have a look on code.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:53
Joined
Oct 29, 2018
Messages
21,358
I want to be specific as I don't got solution from the link. So Can you please have a look on code.
Your code has this:
Code:
Set rs = db.OpenRecordset("SELECT distinct [PayrollFor] FROM [qry_SalarySlipIndividual]", dbOpenSnapshot)
What happens if you change that to this?
Code:
Set rs = fDAOGenericRst("SELECT distinct [PayrollFor] FROM [qry_SalarySlipIndividual]", dbOpenSnapshot)
 

rehanemis

Registered User.
Local time
Today, 11:53
Joined
Apr 7, 2014
Messages
195
Your code has this:
Code:
Set rs = db.OpenRecordset("SELECT distinct [PayrollFor] FROM [qry_SalarySlipIndividual]", dbOpenSnapshot)
What happens if you change that to this?
Code:
Set rs = fDAOGenericRst("SELECT distinct [PayrollFor] FROM [qry_SalarySlipIndividual]", dbOpenSnapshot)
It says Sub or Function not defined.
 

Users who are viewing this thread

Top Bottom