Reputation: 55
I have a query named "Query1" that contains "Report_Name" field. I have also three different Access Reports named "Rpt1, Prt3, and Rpt5". In each records will tell which report name that will be used.
I tried to use if ... then myTestField.visable=true
, but there are too many text-fields in the query to declare in the code.
I also tried to use Subform (child in access?). me.Report_Name = Reports.Rpt5
in 'on Format' in the report form.
Both above cannot complete my need, I do not have much code yet. Is there any idea to achieve this?
Upvotes: 0
Views: 2973
Reputation: 330
This is my best guess as to what you want to accomplish:
Private Sub ButtonPrint_Click()
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db=CurrentDB
Set qdf = db.QueryDefs("YourQuery") 'Change this to your query name
Set rs = qdf.OpenRecordset()
Do While Not rs.EOF
DoCmd.OpenReport rs!Report_Name, acViewPreview, , , acHidden
DoCmd.SelectObject acReport, rs!REPORT_NAME
DoCmd.PrintOut acSelection
DoCmd.Close acReport, rs!Report_Name
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set qdf = Nothing
Set db = Nothing
End Sub
In short, this will open as many reports as rows your query has, in hidden mode and one at a time, printing one at a time as well.
Upvotes: 0