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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print the same report 3 time 1

Status
Not open for further replies.

dixxy

Technical User
Mar 4, 2003
220
0
0
CA
Hello,

I am trying to have the same report preview 3 times, but each time it opens, I would like it to display diferent things. This gets trigered by a button click on a form. This is the code I have:
Code:
Private Sub cmdPrint_Click()
Dim i As Integer

For i = 1 To 3
DoCmd.OpenReport "zqreShipExtraClient", acViewPreview
If i = 1 Then
Reports![zqreShipExtraClient].Label129.Visible = True
Else
Reports![zqreShipExtraClient].Label129.Visible = False

If i = 2 Then
Reports![zqreShipExtraClient].Label130.Visible = True
Else
Reports![zqreShipExtraClient].Label130.Visible = False

If i = 3 Then
Reports![zqreShipExtraClient].Label131.Visible = True
Else
Reports![zqreShipExtraClient].Label131.Visible = False
End If
End If
End If

Next

End Sub

The problem I am getting is that it only opens once. It seems to format 3 times but I only see it once...


Thanks,

Sylvain
 
Place your end if statements after your else statement

If i = 1 then
.....
Else
.....
End if

If ...
...
Else
..
End If

And so on.
You also forgot to put the i in Next i

-mike
 
Mike,

Thanks for your response but It still only opens it once...

It seems to so do the labels alwright, but I only get 1 report with the last label. So I now it goes through alwright, but....


Thanks,

Sylvain
 
I would create a table with three records to store the caption for one label on the report. Add this table to the report's record source and drag the "CaptionField" to the grid. Set the reports top level Sorting and Grouping to [CaptionField] and set it to break before the group. Replace your labels with a text box bound to [CaptionField].

You should now see three copies of the same report. You may need to move previous controls from the Report Header and Footer into the CaptionField Header and Footer sections.

Duane
MS Access MVP
 
Dixxy, dhookom probably has the best idea for dealing with you label issue. The reason your report only opens once is because you open it to Preview the Report and that stops your loop from running any further. If you want to change the label then you can't preview it beforehand with the code set up the way it is. If you change the arugment to just print out the report then your code should run properly.

Paul
 
Duane,

I think I understand where your going with your idea. Now if I try to push this a little furthur, correct me if I am wrong, but in this table that I will be creating, I could ad an other field say 'ReportName'. Now this table could also serve as for the same purpose in other report groups.

Does this make sense?
*********************************************************

Paul,

I did try to change the code to make the report print insted of preview..and I got the same result.

I hope I explained my case clearly enough, once I find out how to make this happened I will make more than one label and textbox apear and disapear from each of the report.(which is actually the same report)...

Thanks,

Sylvain
 
You can add as many fields as you want to your new table. Each field can provide a value for an "instance/section" of your report.

I have seen code before that opens multiple instances of the same form and at least an attempt to do this with reports. The results were never worth the effort.

Duane
MS Access MVP
 
Duane,

Thank very much for the help. The idea of the table with three fields work great!..:)

However, in the process I had to move some of the fields from the 'Report Header' to the 'Page Header', in doing so I get some errors with this:

This is the Address field
Code:
[Address] & ", " & [city] & ", " & [province] & ", " & [postalcode]
Access teels me it can't find the field '[Address] & ", " & [city] & ", " & [province] & ", " & [postalcode]' refered in my expression...yet I have an other text which is Client name set up as follow "=[LastName] & " - " & [Firstname]', and it works just fine. I tried adding an '=' to the address field, but that is not it either.

I don't understand, it was just fine in the 'Report Header', now that it is in the 'Page Header' it doesn't work?????

Any ideas?

Thanks,

Sylvain
 
I had suggested earlier that you create a new primary grouping on the [CaptionField]. This would work better than a page header since your sections may extend over more than one page. You must use the "=" for all expressions other than a single field name.

Duane
MS Access MVP
 
Duane,

You are THE ONE...I read your thread about fifty thiousand times in order to get it right, but I missed using the part about not using 'Page Header'...

The expresiion works without the '='...don't know why, but it works...that's all that matters....thank you very much again.

Thanks,

Sylvain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top