Use a listbox to print different reports.

P

Prohock

I would like to use a listbox to print different reports but I am not able to
program the VB for the print button. I think that with my limited logic that
it should go something like this.

Dim varItem As Variant

For Each varItem In Me!ListPrint.ItemsSelected

Print a corresponding report.

This is pretty vague, but perhaps someone might be able to point me in the
right direction.
 
D

Daniel Pineault

Take a look at Allen's Tip on this subject at:

http://allenbrowne.com/ser-19.html



You might also be interested in the sample databases found at:

http://www.rogersaccesslibrary.com/forum/forum_posts.asp?TID=383&KW=report&PID=383#383
http://www.rogersaccesslibrary.com/forum/forum_posts.asp?TID=382&KW=report&PID=382#382
http://www.rogersaccesslibrary.com/forum/forum_posts.asp?TID=381&KW=report&PID=381#381
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
M

Marshall Barton

Prohock said:
I would like to use a listbox to print different reports but I am not able to
program the VB for the print button. I think that with my limited logic that
it should go something like this.

Dim varItem As Variant

For Each varItem In Me!ListPrint.ItemsSelected

Print a corresponding report.


If the items in the list box's bound column are the exact
names of the reports:
DoCmd.OpenReport Me!ListPrint.ItemData(VarItem), ...

If the report names are not in the bound cloumn, then use
the Column property:
DoCmd.OpenReport Me!ListPrint.Column(X, VarItem), ...
where X is the zero based number of the report names column
in the row source.
 
D

David C. Holley

It's actually incredibly easy. All it takes is a table with five fields - Id
(autonumber), report name, object name, description, where statement. Report
name is the friendly name of the report to display in the list box. Object
name is the actual report that will be opened. Description is a description
of the report (Credit card activity by user and by location). Where
Statement is the criteria to apply to the report.

The list box then needs to pull the Report Name, Id, Object Name and
WhereStatement with the later three hidden by playing with the column widths
as in 2", 0", 0", 0"

Then create a PRINT button with code that pulls the information from the
list box as in...

DoCmd OpenReport lstReports.Column(2),,,,lstReports.Column(3)

Where lstReports.Column(2) is the object name of the report and
lstReports.Column(3) is the where statement to apply.

The description comes into play by having an text box whose control source
is set to pull the description from the table using a DLookup as in

=DLookup("Description","ReportTable","Id =
[Forms]![formNameHere]![lstReports.Column(1)")

Where .Column(1) is the position of the Id field in the list box columns.

Then add code to the list box's onChange event that requeries the text box
for the description which will update the description as a different report
is pulled.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top