Hi All,
I have form in one of my mdb file which gets opened automatically when I open the mdb file. Now I have two combo boxes on that form first one is Region and second one is country and then I have command button to print.
The first combo box gets populated with regions like USA, Asia, Europe etc.. and second combo box is linked to the first one .i.e. it gets populated with the countries which fall under above region for e.g. if I select USA in combobox1 then it will get populated with Brazil, Argentina etc.. that means every time when the region gets changed in the combobox1 the values in combobox2 get changed. Now I use this file for printing some pdf reports, Actually there is only one report in the mdb file but it's used for generating hundred of reports that is I need to print the report for each country of all regions so I will select the region in combobox1 and country in combobox2 and then click on the command button which will preview the "Report1" with the selected country's data same thing will happen for all countries that means the "Report 1" pulls the data from the data according to the country selected in the combobox2. Now as I have hundreds of reports to print in this mdb file I want to automate this process of printing to pdf file with a macro. I have thought of something like below to automate this process :
I got stuck with VBA code. Below is the code which I have so far. I am facing a error .i.e. Run-time error '3061': Too few parameters. Expected 1. in the below code:
When I click on the It highlights the below line from code:
Can you please look into the above codes and help me with the same.
I am facing this difficulty as I haven't worked on ms access much earlier. Please help..
Thanks for your help in advance
I have form in one of my mdb file which gets opened automatically when I open the mdb file. Now I have two combo boxes on that form first one is Region and second one is country and then I have command button to print.
The first combo box gets populated with regions like USA, Asia, Europe etc.. and second combo box is linked to the first one .i.e. it gets populated with the countries which fall under above region for e.g. if I select USA in combobox1 then it will get populated with Brazil, Argentina etc.. that means every time when the region gets changed in the combobox1 the values in combobox2 get changed. Now I use this file for printing some pdf reports, Actually there is only one report in the mdb file but it's used for generating hundred of reports that is I need to print the report for each country of all regions so I will select the region in combobox1 and country in combobox2 and then click on the command button which will preview the "Report1" with the selected country's data same thing will happen for all countries that means the "Report 1" pulls the data from the data according to the country selected in the combobox2. Now as I have hundreds of reports to print in this mdb file I want to automate this process of printing to pdf file with a macro. I have thought of something like below to automate this process :
I got stuck with VBA code. Below is the code which I have so far. I am facing a error .i.e. Run-time error '3061': Too few parameters. Expected 1. in the below code:
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 It highlights the below line from code:
Code:
Set rst = CurrentDb.OpenRecordset("Query1", dbOpenSnapshot)
Code:
Private Sub Command25_Click()
Dim strDefaultPrinter As String
' get current default printer.
strDefaultPrinter = Application.Printer.DeviceName
' switch to printer of your choice:
Set Application.Printer = Application.Printers("PDFCreator")
If Option_Ref_Loc_Bad_Debt_By_Paycode = True Then
DoCmd.OpenReport "Strpt Report", acViewNormal
DoCmd.PrintOut
DoCmd.Close acReport, "Strpt Report", acSaveNo
End If
' Switch back to original default printer
Set Application.Printer = Application.Printers(strDefaultPrinter)
End Sub
I am facing this difficulty as I haven't worked on ms access much earlier. Please help..
Thanks for your help in advance