Printing Multiple reports using one criteria

L

LeBaron

I have created 4 reports on a form, each report individual criteria is
"account number". I want to have a Print All reports button on my form and
only asks for the account number ONCE then all the reports print based on
that account number. If i create a macro and add each report in it, when i
hit the print all button, it asks me 4 times for the number. Isn't there a
better way to use the button or some code i can implement to just ask me one
time for the account number and then all my reports print using that ONE
account number?

Thanks
 
A

Allen Browne

Put a text box on your form, so the user can enter the account number there.

In the query for each of the reports, in the Critiera row under the
appropriate field, tell it to read the value from the text box on the form,
i.e. something like this:
[Forms].[Form1].[Text0]
 
L

LeBaron

thanks Allen for your response, but im using only one query for all 4 reports
and i need to ability to access them individually by the criteria asking for
"account Number" on other forms. So is there another way to have a PRINT ALL
button asks once for just that form im in?
 
A

Allen Browne

The other way is to use the WhereConditon of OpenReport.

This example assumes your table has a Number field named AccountNo, and your
form has a text box named txtAccountNo and a command button named
cmdPreview. The [event Procedure] for the Click event of the button would be
like this:

Private Sub cmdPreview_Click()
Dim strWhere As String
If Not IsNull(Me.txtAccountNo) Then
strWhere = "[AccountNo] = " & Me.txtAccountNo
End If

DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
'etc.
End Sub

If the user leaves the txtAccountNo blank, it then prints ALL records.
 
L

LeBaron via AccessMonster.com

Thanks for your answer, it still asks for the account number on all the
reports because on the query i have a criteria to [Enter Account No:] set.
So when i access reports from other forms, i just input the account number at
that time. But using the code you gave me, it still asks for it 4 times for
all 4 reports even if i have the text box on the form. Is there away around
this without making another copy of my query without the criteria?

Allen said:
The other way is to use the WhereConditon of OpenReport.

This example assumes your table has a Number field named AccountNo, and your
form has a text box named txtAccountNo and a command button named
cmdPreview. The [event Procedure] for the Click event of the button would be
like this:

Private Sub cmdPreview_Click()
Dim strWhere As String
If Not IsNull(Me.txtAccountNo) Then
strWhere = "[AccountNo] = " & Me.txtAccountNo
End If

DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
'etc.
End Sub

If the user leaves the txtAccountNo blank, it then prints ALL records.
thanks Allen for your response, but im using only one query for all 4
reports
[quoted text clipped - 3 lines]
ALL
button asks once for just that form im in?
 
A

Allen Browne

If you use the WhereCondition to filter the report, you don't need the
criteria in the query as well. Remove the criteria from the reports'
queries.

You can't have your cake and eat it too.

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

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

LeBaron via AccessMonster.com said:
Thanks for your answer, it still asks for the account number on all the
reports because on the query i have a criteria to [Enter Account No:] set.
So when i access reports from other forms, i just input the account number
at
that time. But using the code you gave me, it still asks for it 4 times
for
all 4 reports even if i have the text box on the form. Is there away
around
this without making another copy of my query without the criteria?

Allen said:
The other way is to use the WhereConditon of OpenReport.

This example assumes your table has a Number field named AccountNo, and
your
form has a text box named txtAccountNo and a command button named
cmdPreview. The [event Procedure] for the Click event of the button would
be
like this:

Private Sub cmdPreview_Click()
Dim strWhere As String
If Not IsNull(Me.txtAccountNo) Then
strWhere = "[AccountNo] = " & Me.txtAccountNo
End If

DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
'etc.
End Sub

If the user leaves the txtAccountNo blank, it then prints ALL records.
thanks Allen for your response, but im using only one query for all 4
reports
[quoted text clipped - 3 lines]
ALL
button asks once for just that form im in?
 

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