how to print separate report for each record of query in access to pdf

abhay_547

Registered User.
Local time
Today, 18:10
Joined
Dec 4, 2010
Messages
32
Hi All,

I have access database with a form which gets open directly when I open the file. The form has two Comboboxes on it to select the parameters once we select the parameters we can click on the print button and then it opens the report is preview and then we need to hit ctrl + p and print it to pdf there are hundreds of such reports so I want to come up with a code which will print all reports automatically to pdf and then save them on a specific path on local drive. The main issue is there are no separate reports there is one report and then code is querying data on the same report as per the parameters selected by user on the form.

combo boxes gets populated with queries and they are interlinked with query for e.g. Combobox1 gets populated with region and combobox2 gets populated with the country in that region so if you select "Asia" Region in Combobox1 then Combobox2 will get populated with countries like "Singapore", "Japan", "Hongkong" etc. Now you will have to select one of the country and then print report and need to do the same exercise for all regions. Now this means that whenever the selection in combobox1 selection changes the combobox2 requeries it's data in order to populate the respective region countries in it.I want the code to print the files to pdf using "pdfcreator" as printer and then save the files on a specfic path like "C:\".

Below is the code which I have worked on so far but it shows an error that is Run-time error '3061': Too few parameters. Expected 1:

Code:
Private Sub Commandbutton_Click ()
Dim rst As DAO.Recordset
Dim CustomerID As Long
Set rst = CurrentDb.OpenRecordset("Query1", dbOpenSnapshot)
Debug.Print rst
With rst
    Do Until .EOF
        ProgramID = !ProgramID
        DoCmd.OpenReport "StrptReport", acViewPreview, , "CustomerID=" & CustomerID
       Reports![StrptReport].Caption = [FullReportName]
        Name "StrptReport" As [FullReportName] & ".pdf"
        .MoveNext
    Loop
    .Close
End With
Set rst = Nothing
End sub
When I click on the debug error It highlights the below line from code:
Code:
Set rst = CurrentDb.OpenRecordset("Query1", dbOpenSnapshot)


Thanks a lot for your help in advance.:)
 

Users who are viewing this thread

Back
Top Bottom