473,388 Members | 1,427 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,388 software developers and data experts.

Looping through Combo Box to Print Reports

31
I have a report that opens based on the where the office code on the form matches the office code on the report. that works fine.

I have written code that sets the combo box value opens the report (acnormal), then closes report, then sets the combo box value again, opens the report and then close the report.....on and on.

The combo box grows monthly and instead of having to keep updated the code with new office codes, I would like the database to loop through each value of the combo box, print the repot, and then go on to the next one.

Here is the code I am using.
Expand|Select|Wrap|Line Numbers
  1. Dim val As Variant
  2. For Each val In Me.ctrlBranchCode
  3.  
  4. DoCmd.OpenReport "rptBranchProductionWeekMtdYtd", acNormal, , "[Branch Code] = Forms!frmWeeklyMonthlyReporting!ctrlBranchCode"
  5. DoCmd.Close acReport, "rptBranchProductionWeekMtdYtd"
I am gettting an error that says "Object does not support this property or method".

Any help would be greatly appreciated.

A
May 20 '09 #1
9 10196
ADezii
8,834 Expert 8TB
@apank
Here is code that will allow you to return the data in the 'Bound' Column of a Combo Box for each specified Row:
Expand|Select|Wrap|Line Numbers
  1. Dim intCounter As Integer
  2. Dim cboCode As ComboBox
  3.  
  4. Set cboCode = Me![ctrlBranchCode]
  5.  
  6. For intCounter = 0 To cboCode.ListCount - 1
  7.   Debug.Print cboCode.ItemData(intCounter)
  8. Next
May 21 '09 #2
apank
31
@ADezii

The procedure you described worked but I cannot get it to update the combo box, then print the report based on the combo, then close the report and print the next one. I am sure the answer is close but I can't seem to find it.

As always your help is much appreciated.

A
May 21 '09 #3
ADezii
8,834 Expert 8TB
@apank
  1. How are you Updating the Combo Box?
  2. At what specific point are you Updating the Combo Box?
May 21 '09 #4
apank
31
@ADezii
The combo box has a list. I would like the procedure to go through the list, choose each office code listed and print the report(The report prints based WHERE office code = the combo box). I can do it if I hard code the office codes in the procedure and do a set value, but would like it to loop through the combo box instead. That way if new offices are added the report will print automatically.

Thanks
May 22 '09 #5
ADezii
8,834 Expert 8TB
@apank
If the Row Source for the Combo Box is created correctly, what you request 'will' be done automatically.
May 22 '09 #6
apank
31
The series of events should go as follows.
1) Have the report print based on the first branch code in the combo box
2) Close the report
3) Change the branch code in the combo box to the next branch code
4) Print the Report
5) Repeat until the report has been printed for all the branch codes listed.
May 22 '09 #7
ADezii
8,834 Expert 8TB
@apank
Try:
Expand|Select|Wrap|Line Numbers
  1. Dim intCounter As Integer
  2. Dim cboCode As ComboBox
  3.  
  4. Set cboCode = Me![ctrlBranchCode]
  5.  
  6. 'If [Branch Code] is Numeric
  7. For intCounter = 0 To cboCode.ListCount - 1
  8.   DoCmd.OpenReport "rptBranchProductionWeekMtdYtd", acNormal, , _
  9.                    "[Branch Code] = " & cboCode.ItemData(intCounter)
  10.   DoCmd.Close acReport, "rptBranchProductionWeekMtdYtd"
  11. Next
  12.  
  13. 'If [Branch Code] is a String
  14. For intCounter = 0 To cboCode.ListCount - 1
  15.   DoCmd.OpenReport "rptBranchProductionWeekMtdYtd", acNormal, , _
  16.                    "[Branch Code] = '" & cboCode.ItemData(intCounter) & "'"
  17.   DoCmd.Close acReport, "rptBranchProductionWeekMtdYtd"
  18. Next
May 22 '09 #8
apank
31
Thank you very much for this Adezzi. Worked great.
Jun 2 '09 #9
ADezii
8,834 Expert 8TB
@apank
You are quite welcome, apank.
Jun 2 '09 #10

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

Similar topics

0
by: Peter | last post by:
My client has retail shops. All these shops will access retail application through Internet. So sales receipts will be generated from web/application server and send across Internet to shops. ...
0
by: banderas | last post by:
Just wondering if it is possible to use access to create grpahs and even print reports? Is it possible to link excell with access so one can be the date base and when graphs and analytical reports...
2
by: Access Guy | last post by:
I have a procedure to automate .pdf reports. I set the default printer to the pdfwriter driver before running. When the procedure runs, some of the reports get an error: "Cannot print, the file...
0
by: Ian | last post by:
(Sorry if I have repeated this, it did not appear the first time) I have the following code on a button. The idea is that when this button is clicked it prints several reports automatically then...
6
by: Julian | last post by:
Hi, I am a very beginner in databases. I created a database table in Access 2003 and OOo 2.03 that includes name, address, postcode, phone numbers etc of our customers. I would like to sort...
2
by: Kil | last post by:
I designed a form that allows the user to enter dates, and click a checkbox so that certain forms may be loaded. However, I have had trouble getting the right information to load. I would like to...
2
by: Ez | last post by:
I have a MS access database that runs on the network. Few pcs access the database simulataneously every day. The users run a lot of reports from the Access database and print outs always looked...
0
AllusiveKitten
by: AllusiveKitten | last post by:
Hi kind and helpful people... At work I am creating a database and reports that will be used by multiple people. What I need is for my reports to print to a specific colour printer and be manual...
2
by: JM420A | last post by:
I have 3 reports that I need to print sequentially, situation is this R- Report P-Person R1 has 3 pages, one for each P R2 " " R3 " ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.