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

Trying to loop through List Box entries, then save PDF report based on each result...

I have a query used as the source for a report. The query criteria is a List Box (List0). Trying to write code to loop through all of the entries of the List Box and save a separate report for each. Not getting errors -- but also getting a blank report!

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command3_Click()
  2.  
  3. Dim i As Integer
  4. Dim lbox As ListBox
  5. Dim myPath As String
  6. Dim strReportName As String
  7.  
  8. Set lbox = Me![List0]
  9. myPath = "K:\CLE05\Business Resource Center\Opportunity Tracking\"
  10. strReportName = lbox.ItemData(i)
  11.  
  12. For i = 0 To lbox.ListCount - 1
  13.    'Access each item with
  14.    'Me.ListBoxName.ItemData(i)
  15.    DoCmd.OutputTo acOutputReport, "Pipeline - All Rms - AUTO-REPORT", acFormatPDF, myPath & strReportName & ".pdf", False, , , acExportQualityPrint
  16.  
  17.    'Debug.Print lbox.ItemData(i)
  18. Next i
  19.  
  20. End Sub
Aug 20 '15 #1

✓ answered by jimatqsi

I don't know why your report is blank but you will get the same result for every item in the list. Nothing changes as you go through your list. I think you want to move line 10 down between line 14 and 15.

Jim

6 1873
jimatqsi
1,271 Expert 1GB
I don't know why your report is blank but you will get the same result for every item in the list. Nothing changes as you go through your list. I think you want to move line 10 down between line 14 and 15.

Jim
Aug 22 '15 #2
Got the answer from a different forum -- but here is the answer:
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. Dim lbox As ListBox
  3. Dim myPath As String
  4. Dim strReportName As String
  5. Dim varItm As Variant
  6. Dim str As String
  7.  
  8. str = ""
  9. Set lbox = Me!List0
  10. myPath = "C:\Users\ROSENBR\Documents\BRC\Report\"
  11.  
  12. If lbox.ItemsSelected.Count = 0 Then
  13. MsgBox ("No items are currently selected.")
  14. Exit Sub
  15. End If
  16.  
  17. For Each varItm In lbox.ItemsSelected
  18.         strReportName = lbox.Column(0, varItm)
  19.             Debug.Print "chcking Loop logic with " & lbox.Column(0, varItm)
  20.             Debug.Print "2nd debug:" & strReportName
  21.             Debug.Print "[RM_FULL_NAME]= " & """" & lbox.Column(0, varItm) & """"
  22.     DoCmd.OpenReport "Pipeline - All Rms - AUTO-REPORT", acViewPreview, , "[RM_FULL_NAME]=" & """" & strReportName & """", acWindowNormal
  23.     DoCmd.OutputTo acOutputReport, "Pipeline - All Rms - AUTO-REPORT", acFormatPDF, myPath & strReportName & ".pdf", False, , , acExportQualityPrint
  24.     DoCmd.Close acReport, "Pipeline - All Rms - AUTO-REPORT", acSaveNo
  25. Next varItm
Aug 25 '15 #3
NeoPa
32,556 Expert Mod 16PB
I'm very curious to know why you needed to go elsewhere when the correct answer was posted here two days ago?
Aug 25 '15 #4
NeoPa:
I'm very curious to know why you needed to go elsewhere when the correct answer was posted here two days ago?
Actually -- that wasn't the correct answer for the problem I was trying to solve.
Aug 25 '15 #5
NeoPa
32,556 Expert Mod 16PB
I'm happy to read your reasoning on this.

I read through the code and it seemed to me to be exactly what your code was suffering from. In the absence of your posting what happened when you tried it, I'm still of that opinion.
Aug 25 '15 #6
jimatqsi
1,271 Expert 1GB
And I notice that the corrected code did in fact show the line moved into your loop as I suggested it needed to be. So what I pointed out was at least part of your problem. But I note that there was also the problem of the blank report which was mentioned but not really explained.

I'm glad you got your problem resolved.
Aug 26 '15 #7

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

Similar topics

1
by: gregoryenelson | last post by:
Hi all. I have created a Report with a graph also on it. The users, working through a form only (not the DB window) will want to view that Report run numbers of times against different criteria,...
3
by: cassey14 | last post by:
Hi I hope someone help me on this.. I need to attach any files in my form like word,excel etc and save it on database..and also I need to open it at the same time..please help me... and also im...
5
by: jonosborne | last post by:
Hi, i have managed to filter a report based on selections made in a list box but am totally confused with a message box that appears everytime i run my report. Let me explain (i apologise for...
12
by: micarl | last post by:
How would i print a report based on criteria selected from several Combo Boxes as well as multiple Multi Select List Boxes, that are located on the same form? I can get one Multi List Box, just...
1
by: Neobeowulf | last post by:
Team, I'm totally stumped on this one. I'm trying to create a button called "Run Report" that opens a report based off a selection made in a combo box then filtered by a column in the report...
5
by: shawnrye1980 | last post by:
I have a table that has 15 managers and I have queries that I need for there employees I have 5 union all queries because there are too many where clauses, I have done this and based off the main...
1
by: sroseindy | last post by:
PLEASE HELP - I NEED THIS TO COMPLETE A CONTRACT!!! Hi all, I have a report based on a crosstab query. The number of columns is dynamic based on the selection criteria the user chooses. I’ve set up...
6
Seth Schrock
by: Seth Schrock | last post by:
I may be trying the impossible. I'm trying to print multiple records on preprinted forms. However, each record may be on different forms. There will always be at least to different formats. So...
2
by: fredmart | last post by:
Hi, I'm having problems finding a way to apply conditional formatting based on comparing the text contents of two fields in two different tables. What I'd like to do: I've got two tables that...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...

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.