Print a multiple reports from a single button, can it be done

M

Michael

I want to print different reports from one button. In a perfect world, I
would like to have the code direct each report to a different printer. I
currently have the following code for my button which has one of Allen
Browns calendar on it.
here is the code
thank you
Michael

Private Sub ok_Click()
Dim strReport As String 'Name of report to open.
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenReport.
Const conDateFormat = "\#mm\/dd\/yyyy\#"

strReport = "Order Details"
strField = "[Data Partenza]"

If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date, but no start.
strWhere = strField & " < " & Format(Me.txtEndDate,
conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then 'Start date, but no End.
strWhere = strField & " > " & Format(Me.txtStartDate,
conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.txtStartDate,
conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If

' Debug.Print strWhere 'For debugging purposes only.
DoCmd.OpenReport strReport, acViewPreview, , strWhere

End Sub
 
A

Allen Browne

You can use multiple OpenReport statments in the button's Click event
procedure, e.g.:
DoCmd.OpenReport "Report1", acViewPreview
DoCmd.OpenReport "Report2", acViewPreview
and so on.

Use the same WhereCondition for them if you wish (and if the field names are
the same.)

You can assign a report to a particular printer by opening it in design
view, and choosing:
File | Page Setup | Page | Use Specific Printer
Then save the report, and it will remember to go to that printer each time.

If you need to assign the report to a printer that is not available at
design time, (e.g. where you are a developer who has no idea what printers
your end user will have), see:
Printer Selection Utility
at:
http://allenbrowne.com/AppPrintMgt.html
 
M

Michael

your really amazing... can I take you home??? your better than a loyal
puppy?
michael

Allen Browne said:
You can use multiple OpenReport statments in the button's Click event
procedure, e.g.:
DoCmd.OpenReport "Report1", acViewPreview
DoCmd.OpenReport "Report2", acViewPreview
and so on.

Use the same WhereCondition for them if you wish (and if the field names
are the same.)

You can assign a report to a particular printer by opening it in design
view, and choosing:
File | Page Setup | Page | Use Specific Printer
Then save the report, and it will remember to go to that printer each
time.

If you need to assign the report to a printer that is not available at
design time, (e.g. where you are a developer who has no idea what printers
your end user will have), see:
Printer Selection Utility
at:
http://allenbrowne.com/AppPrintMgt.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Michael said:
I want to print different reports from one button. In a perfect world, I
would like to have the code direct each report to a different printer. I
currently have the following code for my button which has one of Allen
Browns calendar on it.
here is the code
thank you
Michael

Private Sub ok_Click()
Dim strReport As String 'Name of report to open.
Dim strField As String 'Name of your date field.
Dim strWhere As String 'Where condition for OpenReport.
Const conDateFormat = "\#mm\/dd\/yyyy\#"

strReport = "Order Details"
strField = "[Data Partenza]"

If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then 'End date, but no start.
strWhere = strField & " < " & Format(Me.txtEndDate,
conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then 'Start date, but no End.
strWhere = strField & " > " & Format(Me.txtStartDate,
conDateFormat)
Else 'Both start and end dates.
strWhere = strField & " Between " & Format(Me.txtStartDate,
conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If

' Debug.Print strWhere 'For debugging purposes only.
DoCmd.OpenReport strReport, acViewPreview, , strWhere

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top