473,395 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to Display the Copy Number in a report

mshmyob
904 Expert 512MB
I am using Access 2007 but any VBA code will probably work.

I need to display which copy number I have printed.

For example if the user prints 4 copies I need to display the following in the page footer of each copy respectively:
Copy 1
Copy 2
Copy 3
Copy 4

Any ideas would be appreciated.

If you can get it to show Copy 1 of 4, Copy 2 of 4, etc that would be even better.
Jan 7 '08 #1
12 5008
MMcCarthy
14,534 Expert Mod 8TB
I haven't really thought about this but two things immediately pop to mind.

First one is that you will have to create a public variable to hold the total number of copies to be printed. A value which will have to be entered by the user when sending to print.

Secondly, you will need to look at creating some kind of loop in the on Print procedure of the report. Then somehow increment from one to the value stored in the public variable.
Jan 8 '08 #2
mshmyob
904 Expert 512MB
Thanks. I already ask for the number of copies so I have that as a variable in another form. So I will make it public and pass it along to the report and try and create a counter.

I don't know if the counter will clear each time a copy of the report is printed but I will give it a try and let you know.

I haven't really thought about this but two things immediately pop to mind.

First one is that you will have to create a public variable to hold the total number of copies to be printed. A value which will have to be entered by the user when sending to print.

Secondly, you will need to look at creating some kind of loop in the on Print procedure of the report. Then somehow increment from one to the value stored in the public variable.
Jan 8 '08 #3
mshmyob
904 Expert 512MB
Ok I have tried passing variables and it won't work. I think I figured out why and if anyone can figure out a better way I would appreciate it.

I open my report from a form but set the number of copies like so
Expand|Select|Wrap|Line Numbers
  1. Dim rpt As Report
  2.     Dim strDefaultPrinter  As String
  3.     ' get current default printer.
  4.     strDefaultPrinter = Application.Printer.DeviceName
  5.     ' switch to printer of your choice:
  6.     Set Application.Printer = Application.Printers(strDefaultPrinter)
  7.     ' open report but in hidden mode so you can apply parameters to it such as number of copies to print
  8.     DoCmd.OpenReport "PickSlip", acViewPreview, , , acHidden
  9.     ' set my parameters for the print job
  10.     Set rpt = Reports!PickSlip
  11.     rpt.Printer.Copies = cmbCopiesPick.Value
  12.       ' activate my print job by unhiding it
  13.     DoCmd.OpenReport "PickSlip", acViewNormal
  14.      DoCmd.Close acReport, "PickSlip", acSaveNo
  15.       Set Application.Printer = Nothing
  16.  
This code sets the number of copies for the printer to print.
I then open the report and it prints.

The problem is that the report looks at it as printing a single report and the printer controls the number of prints.

I guess I could change the code and have say 4 lines of docmd.openreport and each one would be a copy but that seems very ineficient.

Anyone know any other way other than having multiple docmd.openreport commands.





I haven't really thought about this but two things immediately pop to mind.

First one is that you will have to create a public variable to hold the total number of copies to be printed. A value which will have to be entered by the user when sending to print.

Secondly, you will need to look at creating some kind of loop in the on Print procedure of the report. Then somehow increment from one to the value stored in the public variable.
Jan 8 '08 #4
MMcCarthy
14,534 Expert Mod 8TB
I'll see if any of the other experts are aware of anything.
Jan 8 '08 #5
Rabbit
12,516 Expert Mod 8TB
What if you looped the print command while at the same time incrementing a print count variable? And then calling those controls from the report?

Expand|Select|Wrap|Line Numbers
  1. Dim CurrentCount As Integer, MaxCount As Integer
  2.  
  3. MaxCount = txtMaxCount
  4.  
  5. For CurrentCount = 1 To MaxCount
  6.    txtCurrentCount = CurrentCount
  7.    DoCmd.OpenReport "rpt_Name"
  8. Next CurrentCount
  9.  
Jan 8 '08 #6
Scott Price
1,384 Expert 1GB
This is just a brain´storming suggestion since I´m not at my main computer and can´t do any testing on the computer I´m using to write this, but don´t forget the .Print method.

Again from the top of my head I´m thinking of a function that would recieve the number of copies from a public variable, and increment them, then by directly printing to the page (which is the advantage of the .Print method, doing away with the need to tie your variables to report controls) you thereby have greater and easier control over what you are wanting to do.

Just ideas, good luck, and I´ll keep an eye on this as much as I can. I´m still, unfortunately, not at a firm location yet, but will be getting back to normal in the next week.

Regards,
Scott
Jan 8 '08 #7
NeoPa
32,556 Expert Mod 16PB
From my understanding of printing multiple copies of a report (using the .Copies property) it would be impossible to do what you ask as they are just that - copies.

To produce the result that you want you would need to take the approach suggested and code printing of the report n times (with one copy each time). This is slightly different as certain variables (like Print Date & Print Time would be different using this approach but exactly the same when using the .Copies approach.

To get a public variable to be accessed by an object like a report in the newer versions of Access (I don't use 2007 but I've noticed even 2003 is stricter in this than 2000 was and that was more so than 97) you will need to define a public function to return the value required. In the new versions it's probably worth designing a function with increased flexibility to handle passing various values as I anticipate it being required more with the newer strictures. I'm afraid I can't provide an example now as I'm only just starting to find some 2003 users on my databases at work. I expect I will have one in the not too distant future, but that won't help you now I'm afraid.
Jan 9 '08 #8
mshmyob
904 Expert 512MB
By the sounds of it I will need to scrap the code I have for the number of copies and use a counter loop and the openargs property to pass a variable to the report. I will re-code and let you guys know how it worked out.

It's too bad Access doesn't have the function built into the report for copies like they do for page counts.

From my understanding of printing multiple copies of a report (using the .Copies property) it would be impossible to do what you ask as they are just that - copies.

To produce the result that you want you would need to take the approach suggested and code printing of the report n times (with one copy each time). This is slightly different as certain variables (like Print Date & Print Time would be different using this approach but exactly the same when using the .Copies approach.

To get a public variable to be accessed by an object like a report in the newer versions of Access (I don't use 2007 but I've noticed even 2003 is stricter in this than 2000 was and that was more so than 97) you will need to define a public function to return the value required. In the new versions it's probably worth designing a function with increased flexibility to handle passing various values as I anticipate it being required more with the newer strictures. I'm afraid I can't provide an example now as I'm only just starting to find some 2003 users on my databases at work. I expect I will have one in the not too distant future, but that won't help you now I'm afraid.
Jan 9 '08 #9
NeoPa
32,556 Expert Mod 16PB
You're showing a fine attitude here and I hope we can help you some more (or maybe even that you won't need more help) when you've adjusted your code.
However, I feel you're labouring under a misaprehension about copies. The property and the term.
  1. .Copies are a property of the print and not managed by Access at all (other than to pass the request on to the printer driver.
  2. A copy would NOT be a copy if it were not exactly the same. As soon as you introduce a copy counter into the printed output, it ceases to be a copy. Using the term loosely it may be used in general parlance, however the name "Copies" was chosen precisely to match the facility provided.
That's not at all to say that what you want to do can't be done, or even that you shouldn't refer to the results as copies. Just bear in mind that there will always be a level of ambiguity when terming them thus.
Jan 9 '08 #10
mshmyob
904 Expert 512MB
You are right about the definition of copy - If i add Copy 1 to the first copy and then Copy 2 to the 2nd etc. then they are not true copies.

My previous code was setting the printer copies like you say and therefore Access has no way to do what I want because it actually sends only one version of the report to the printer and the printer then just ejects how many copies its copy setting is set to.

I have redone my code to send individual docmd.openreport commands inside a loop and used the openargs parameter to send a number string representing the copy number. This works fine now.

I thank everyone for all their input, it put me on the right track. Sometimes you get so tied up in trying to solve something based on code that is already working that you just end up going in circles until someone gives you a knock upside the head.

You're showing a fine attitude here and I hope we can help you some more (or maybe even that you won't need more help) when you've adjusted your code.
However, I feel you're labouring under a misaprehension about copies. The property and the term.
  1. .Copies are a property of the print and not managed by Access at all (other than to pass the request on to the printer driver.
  2. A copy would NOT be a copy if it were not exactly the same. As soon as you introduce a copy counter into the printed output, it ceases to be a copy. Using the term loosely it may be used in general parlance, however the name "Copies" was chosen precisely to match the facility provided.
That's not at all to say that what you want to do can't be done, or even that you shouldn't refer to the results as copies. Just bear in mind that there will always be a level of ambiguity when terming them thus.
Jan 9 '08 #11
sierra7
446 Expert 256MB
Hi

I have found that the easiest way to print things like Date Ranges or Filter Criteria on a report is to keep an underlying form open.Passing variable never worked and this save creating them anyway. The Control Source for the text box control on the report then just reference the controls on the form. These can be quite complicated e.g.
Expand|Select|Wrap|Line Numbers
  1. =[Forms]![dialogRecalls]![DatesBetween_Text] & " (Week " & [Forms]![dialogRecalls]![cmbFrom] & " to Week " & [Forms]![dialogRecalls]![cmbTo] & ")"
where here the underlying form is called dialogRecalls and things in square boxes are controls on my form.

You can set the form's Visible=False when you click the Print button and then close the form on the Report close event.
Expand|Select|Wrap|Line Numbers
  1. If IsLoaded("dialogRecalls") then DoCmd.Close accForm, "dialogRecalls"
(IsLoaded is a standard procedure in Access) So, if I had your problem I would set up a loop on my Print button to count the number of reports wanted and send separate print commands for each copy, updating a text box on my form with the current copy. That way I could easily do the 'Copy 1 of 4' as you requested.

The Control Sourcs for the text box in your footer would be something like;
Expand|Select|Wrap|Line Numbers
  1. ="Copy " & [Forms]![frmDialog]![CurrentCopy] & " of " & [Forms]![frmDialog]![LastCopy] 
where frmDialog is the form you are using to send the print commands and [CurrentCopy] and [LastCopy] are text boxes displaying the counts.I have not actually tested this and would be wary that the loop may have to wait for confirmation that the first report is complete before incrementing the copy number and sending the second print command.

But I would try it as a first step to see whether it is a problem.

Best of luck

S7
Jan 9 '08 #12
mshmyob
904 Expert 512MB
Thanks for the input Si.

It's basically what I have done. I always leave the form open to reference variables as you do. I created a loop and pass the copy number using the openargs parameter in the openreport method. I have a text box in the page footer and it references the openarg parameter passed to it when the report gets opened.

Hi

I have found that the easiest way to print things like Date Ranges or Filter Criteria on a report is to keep an underlying form open.Passing variable never worked and this save creating them anyway. The Control Source for the text box control on the report then just reference the controls on the form. These can be quite complicated e.g.
Expand|Select|Wrap|Line Numbers
  1. =[Forms]![dialogRecalls]![DatesBetween_Text] & " (Week " & [Forms]![dialogRecalls]![cmbFrom] & " to Week " & [Forms]![dialogRecalls]![cmbTo] & ")"
where here the underlying form is called dialogRecalls and things in square boxes are controls on my form.

You can set the form's Visible=False when you click the Print button and then close the form on the Report close event.
Expand|Select|Wrap|Line Numbers
  1. If IsLoaded("dialogRecalls") then DoCmd.Close accForm, "dialogRecalls"
(IsLoaded is a standard procedure in Access) So, if I had your problem I would set up a loop on my Print button to count the number of reports wanted and send separate print commands for each copy, updating a text box on my form with the current copy. That way I could easily do the 'Copy 1 of 4' as you requested.

The Control Sourcs for the text box in your footer would be something like;
Expand|Select|Wrap|Line Numbers
  1. ="Copy " & [Forms]![frmDialog]![CurrentCopy] & " of " & [Forms]![frmDialog]![LastCopy] 
where frmDialog is the form you are using to send the print commands and [CurrentCopy] and [LastCopy] are text boxes displaying the counts.I have not actually tested this and would be wary that the loop may have to wait for confirmation that the first report is complete before incrementing the copy number and sending the second print command.

But I would try it as a first step to see whether it is a problem.

Best of luck

S7
Jan 9 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mary | last post by:
I need to display 10 fields (columns) to display in a crystal Report. When I am trying to print the report some of the columns are cutting off from the report. Is there any way to display the...
2
by: Bill | last post by:
I have the user fill in a form and then click a control to send a notice to the lab that the form has been filled in along with the file reference number. I'd like to attach a copy of the form to...
3
by: Saintor | last post by:
I have a record with with a quantity value. I have to print one record for each quantiy with a counter, incrmementing on each copy. I wan't to avoid to use many docmd.openreport instructions. ...
1
by: Edward | last post by:
ASP.NET SQL Server 2k Our clients need to output a pretty complicated Consignment/Delivery Note from their system. It is in tabular form, but each row can have a) a different number of...
5
by: GB | last post by:
Okay, here is what I am trying to do We have a dialog of windows that collects information for generation of a dynamic HTML report. The last page in the wizard dialog accepts all report options...
1
by: ZinksInk | last post by:
How do I make a report display the current record open in a form? This seems like it should be a simple issue however I am strugling to figure out what code SQL / Querry I should use to do this....
2
by: Jimmy | last post by:
On the subreport, records are grouped by WorkDate. In the WorkDate header there is a textbox named DateCounter with the control source =1 and running sum set to yes. In either the report footer or...
2
by: Vayse | last post by:
On my Help/About screen, I'd like to display 1) The version number, as it appears in the Publish screen. 2) The version number of the Report Viewer control. How would I do this? Thanks Vayse
6
by: Gord | last post by:
I have a report whose Record Source I set in code when clicking on a command button on a form. This Record Source is a table that gets created by the code. I have a textbox on the report whose...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.