Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop report with values in a table

Status
Not open for further replies.

blindlemonray

Technical User
Nov 24, 2003
130
GB
I am trying to output a report to a printer several times but change the report content based on the value of each row in a table.

I can loop for each value in the table and print a report. But I cannot figure out how to use the value of each row as a criteria in the report.

So I have a report and instead of creating a report for each user and printing, create a table of users and then print the report for each user in the table using the table as the criteria in the report.

Code shown below if it helps

Code:
Private Sub Command69_Click()
Dim cnCurrent As ADODB.Connection
Dim rsCallers As ADODB.Recordset

Set cnCurrent = CurrentProject.Connection
Set rsCallers = New ADODB.Recordset

rsCallers.Open "Accmans", cnCurrent, adOpenDynamic, adLockOptimistic

Do Until rsCallers.EOF
    DoCmd.OpenReport "user", acViewNormal
rsCallers.MoveNext
If rsCallers.EOF Then Exit Do
Loop
Exit Sub

End Sub

any help really appreciated.
 
you can use the where Condition

Code:
DoCmd.OpenReport "user", acViewNormal,,"user=" Accmans!user

but even better will be to join the Accmans(table/query) to the reports recordsource
 
You can use the Where statement:

DoCmd.OpenForm "user", acViewNormal, , "SomeNumericField=" & rsCallers!SomeNumericField

You will need delimiters for anything other than text fields.
 
thanks peeps, but when I try this it prints the report for all the entries in the accmans table in one report. what I need is for it to print with each name in the table individually. So Accmans 1 then Accmans 2, etc. Can I somehow use a sort of current row filter??
 
Please post the code as modified to suit your application.
 
Code as shown below:-

Code:
Dim cnCurrent As ADODB.Connection
Dim rsCallers As ADODB.Recordset

Set cnCurrent = CurrentProject.Connection
Set rsCallers = New ADODB.Recordset

rsCallers.Open "Accmans", cnCurrent, adOpenDynamic, adLockOptimistic

Do Until rsCallers.EOF
    DoCmd.OpenReport "Ashley", acViewPreview, User_name = " & rsCallers!user"
rsCallers.MoveNext
If rsCallers.EOF Then Exit Do
Loop
Exit Sub
 
perhaps if User_name is a text field then

Code:
Dim cnCurrent As ADODB.Connection
Dim rsCallers As ADODB.Recordset

Set cnCurrent = CurrentProject.Connection
Set rsCallers = New ADODB.Recordset

rsCallers.Open "Accmans", cnCurrent, adOpenDynamic, adLockOptimistic

Do Until rsCallers.EOF
    [COLOR=red]DoCmd.OpenReport "Ashley", acViewPreview, "User_name = '" & rsCallers!user & "'" [/color]
rsCallers.MoveNext
If rsCallers.EOF Then Exit Do
Loop
Exit Sub
 
Tip: use the Option Explicit instruction.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top