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

Print Button - modify to print multiple copies? 2

Status
Not open for further replies.

SherryLynn

Technical User
Feb 4, 2001
171
CA
Hi there,

I have a Tabbed Form (with subforms) on which I have placed a Print button. The Print button is linked to a Report. How do I get the Print button to print 3 copies of the specified Report?

Thanks in advance,
Sherry
 
This is crude but effective:


'Add to Print Button Code
stDocName = "Your Report Name"
DoCmd.OpenReport stDocName, acNormal
DoCmd.OpenReport stDocName, acNormal
DoCmd.OpenReport stDocName, acNormal



Cheers,
 
Hello,

Thank you for the code. I am a novice with VBA - could you tell me where specifically I need to place this? Do you mean in the OnClick Event Procedure?

Thanks
Sherry
 
I think the following should help.


You can place the code in the On Click of the button the you use to print. If you have something else in properties, such as a macro, that refers to printing, delete it.

HTH

An investment in knowledge always pays the best dividends.
by Benjamin Franklin
Autonumber Description - FAQ702-5106
 
Hello,

Ok, I did what you suggested (I figured out where to put that code as soon as I opened the code window). :). The problem for me is that the report which is being printed is based on a parameter query. So, when I do as you suggested above, I have to type in the parameters three times. Is there a way to have it do this, but ask for the parameters only once?

Thanks again :)
Sherry
 
Not sure if I understand about the paramaters. It may be a matter of terminology. I think you may mean criteria. Prior to using the above code, did you have to enter any paramater? If so, what and how many times? Try opening the paramater query by itself and see what occurs.

An investment in knowledge always pays the best dividends.
by Benjamin Franklin
Autonumber Description - FAQ702-5106
 
Hello,

The print button pulls a report that is based on a query. The query asks for certain criteria in order to pull the correct record. For example, when I run the query it asks me for a File# and an Area. Once I type these in, it produces a report with the information from that particular record. The print button I currently have works fine (I've posted the code below), but I want 3 copies to print instead of just one. Currently if I want 3 copies I have to go through the process three times. I went to the document you referred me to, but I can't seem to get it to work properly for me. It prints 2 copies of the Report and then 3 copies of the Form??? I'm very inexperienced with code, so I need specifics on where to put the code and what exactly to enter. All your help is much appreciated.


Private Sub PrintStat_Click()
On Error GoTo Err_PrintStat_Click

Dim stDocName As String

stDocName = "Stats-Current Family"
DoCmd.OpenReport stDocName, acNormal

Exit_PrintStat_Click:
Exit Sub

Err_PrintStat_Click:
MsgBox Err.Description
Resume Exit_PrintStat_Click

End Sub

Thanks, Sherry
 
Replace this:
DoCmd.OpenReport stDocName, acNormal
By this:
DoCmd.SelectObject acReport, stDocName, True
DoCmd.PrintOut , , , , 3

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

I replaced the line of code with what you suggested. A couple of problems. First of all it is printing 6 copies of the report instead of 3. I'm not sure why?? Also, it pops the database window up in front of my form when I select this print button. Can I keep it from doing that?

Thanks for your help.

Sherry
 
Hi PHV,

I figured out why it printed the six copies - I didn't realize that there were two records for the particular section I tested (therefore 3 + 3). But, it still is popping up that db window. Any thoughts?

Sherry
 
You may try this instead :
DoCmd.OpenReport stDocName, acViewPreview
DoCmd.PrintOut acPages, , , , 3


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,

Thank you - that works beautifully! Now, one last question if you don't mind. Can I program this button to pick the current record that I have open?

I think there is a way, but I don't have any experience with that. Thanks Again!

Sherry
 
Take a look at the DoCmd.OpenReport method, the 4th argument (WhereCondition).

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I'm sorry, I'm not understanding what you mean?

Sherry
 
With the cursor inside the word OpenReport in your code press the F1 Key.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello,

Ok, I'm trying, but I'm missing something. I have tried setting this up, but it wants to print every record from my database. I am pasting the code here hoping that someone can help me "refine" it.

Private Sub PrintStat_Click()
On Error GoTo Err_PrintStat_Click

Dim stDocName As String
Dim stFilter As String
stDocName = "Stats-Current Family"
stFilter = "FamilyID = Forms!FamilyTabbed!FamilyID"
DoCmd.OpenReport stDocName, acViewPreview
DoCmd.PrintOut acPages, , , , 3

Exit_PrintStat_Click:
Exit Sub

Err_PrintStat_Click:
MsgBox Err.Description
Resume Exit_PrintStat_Click

End Sub

Thanks,
Sherry
 
Replace this:
stFilter = "FamilyID = Forms!FamilyTabbed!FamilyID"
DoCmd.OpenReport stDocName, acViewPreview
By this:
stFilter = "FamilyID = '" & Forms!FamilyTabbed!FamilyID & "'"
DoCmd.OpenReport stDocName, acViewPreview, , stFilter
If FamilyID is defined as numeric in the underlaying table then get rid of the single quotes.


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Here is what I did. When I click on the button it is asking for "FamilyID"? Shouldn't it be getting that from the form?


Private Sub PrintStat_Click()
On Error GoTo Err_PrintStat_Click

Dim stDocName As String
Dim stFilter As String
stDocName = "Stats-Current Family"
stFilter = "FamilyID = '" & Forms!FamilyTabbed!FamilyID & "'"
DoCmd.OpenReport stDocName, acViewPreview, , stFilter
DoCmd.PrintOut acPages, , , , 3

Exit_PrintStat_Click:
Exit Sub

Err_PrintStat_Click:
MsgBox Err.Description
Resume Exit_PrintStat_Click

End Sub
 
Isn't FamilyID the name of a field in the report's underlaying query ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yes, FamilyID is a field in the underlying query of the report.

When I use the button now, I get the following error message:

"This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables".

The FamilyID field is in the query. It is also on the report.

I don't know what I have done wrong. The form is a Tabbed form with subforms. The FamilyID field is on the Main form, and the second tabbed form. Does this make a difference?

Here is the code:

Private Sub PrintStat_Click()
On Error GoTo Err_PrintStat_Click

Dim stDocName As String
Dim stFilter As String
stDocName = "Stats-Current Family"
stFilter = "FamilyID = '" & Forms!FamilyTabbed!FamilyID & "'"
DoCmd.OpenReport stDocName, acViewPreview, , stFilter
DoCmd.PrintOut acPages, , , , 3

Exit_PrintStat_Click:
Exit Sub

Err_PrintStat_Click:
MsgBox Err.Description
Resume Exit_PrintStat_Click

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top