Print Record From Mutiple Reports

beachy

Registered User.
Local time
Today, 16:10
Joined
Mar 26, 2010
Messages
11
Hi,

I currently have a SOP database which holds all of my customer discount information. The discount information is broken down into three different tables due to the data being incompatible. As a result I have generated three different reports which has a different page for each customer which has that particular discount. Not all customers have a discount or have one or two out of the three.

So far I have written this:

Private Sub Command0_Click()

'Print current record

If IsNull(Me!txtAccountNo) Then
MsgBox "Please select a valid record", _
vbOKOnly, "Error"
Exit Sub

End If

DoCmd.OpenReport "rptInHouseReports_DiscountCodes", , , _
"[CU Search Name] = """ & Forms![frmDiscount].[txtAccountNo] & """"

DoCmd.OpenReport "rptInHouseReports_DiscountProducts", , , _
"[CU Search Name] = """ & Forms![frmDiscount].[txtAccountNo] & """"

DoCmd.OpenReport "rptInHouseReports_DiscountRolls", , , _
"[CU Search Name] = """ & Forms![frmDiscount].[txtAccountNo] & """"

End Sub

This checks to see if an account number has been entered in the text box and then prints the reports. It currently tries to print all three reports even if no data is present within each report.

What I need to end up with is the ability to select a customer as we currently have but only print the reports which are relevant to the customer. We also more importantly at the moment need to be able to print all customers which have data in one or more of the reports.

I then edited the code which should close the report automatically if no data is found (or so I am told!):

'Print current record

If IsNull(Me!txtAccountNo) Then
MsgBox "Please select a valid record", _
vbOKOnly, "Error"
Exit Sub

End If

On Error Resume Next
DoCmd.OpenReport "rptInHouseReports_DiscountCodes", , , _
"[CU Search Name] = """ & Forms![frmDiscount].[txtAccountNo] & """"
If Err = 2501 Then Err.Clear

On Error Resume Next
DoCmd.OpenReport "rptInHouseReports_DiscountProducts", , , _
"[CU Search Name] = """ & Forms![frmDiscount].[txtAccountNo] & """"
If Err = 2501 Then Err.Clear

On Error Resume Next
DoCmd.OpenReport "rptInHouseReports_DiscountRolls", , , _
"[CU Search Name] = """ & Forms![frmDiscount].[txtAccountNo] & """"
If Err = 2501 Then Err.Clear

End Sub


I logically need to insert a loop into the code so that it will cycle through all of the records. The easiest way I can think of doing this is to go through every record in the customer table (tblCustomers) to see if there is any data in each report and if yes print if not move on to the next report or customer. Is there an easy way to do this?

I have looked through the other threads relating to printing multiple reports for a record but I cant get my head around how it relates to what I am trying to achieve!

Any help is much appreciated!

Thanks in advance
 
Last edited:
This checks to see if an account number has been entered in the text box and then prints the reports. It currently tries to print all three reports even if no data is present within each report.

What I need to end up with is the ability to select a customer as we currently have but only print the reports which are relevant to the customer. [\QUOTE]

OK, after reading my own post I have managed to sort out the reports printing even if no record is present.

My code now looks like this:

'Print current record

If IsNull(Me!txtAccountNo) Then
MsgBox "Please select a valid record", _
vbOKOnly, "Error"
Exit Sub

End If

DoCmd.OpenReport "rptInHouseReports_DiscountCodes", , , _
"[CU Search Name] = """ & Forms![frmDiscount].[txtAccountNo] & """"

DoCmd.OpenReport "rptInHouseReports_DiscountProducts", , , _
"[CU Search Name] = """ & Forms![frmDiscount].[txtAccountNo] & """"

DoCmd.OpenReport "rptInHouseReports_DiscountRolls", , , _
"[CU Search Name] = """ & Forms![frmDiscount].[txtAccountNo] & """"


Exit Sub

ErrorHandler:

' This traps the Output to Error message
If Err = 2501 Then
Resume Next

Else
MsgBox Err.Description
Resume Next

End If

I still need help cycling through all records though!
 

Users who are viewing this thread

Back
Top Bottom