vba coding

J

Jessica

Hi Everyone,


I want to set up a form where the user selects a UPC number or many UPC
numbers from a list box and then clicks on the button where a certain
report will be previewed or printed of the information of just the UPC
numbers that were selected. I will have over 500 UPC numbers in my table
and probably 5 different reports. The thing is, can I have it so that a
UPC range is directed to a certain report. i.e upc between the range of
1111 to 3333 will be printed using report 1, 4444 to 6666 will be
printed using report 2, and everything else not in these ranges will be
printed using report 3.

Thanks,
Jess
 
R

Rob Parker

The following code should help you:

Private Sub cmdOpenReports_Click()
Dim varSelectedUPC As Variant
Dim lngUPC as Long

For Each varSelectedUPC In lstUPC.ItemsSelected
lngUPC = lstUPC.ItemData(varSelectedUPC)
Select Case lngUPC
Case 1111 to 3333
DoCmd.OpenReport "report1", acViewPreview, ,"UPC = " & lngUPC
'preview report; change to acViewormal to print immediately
Case 4444 to 6666
DoCmd.OpenReport "report2", acViewPreview, ,"UPC = " & lngUPC
Case Else

DoCmd.OpenReport "report3", acViewPreview, ,"UPC = " & lngUPC
End Select
Next varSelectedUPC
End Sub

This assumes that your list box is named lstUPC (multi-select, with UPC
being the bound column), that your reports have a recordset which includes
UPC (which is a number), and that you want a separate report
previewed/printed for each UPC (rather than a single report for all UPCs
within a range). You should probably add error checking/trapping to cope
with no data, or ... It's up to you where you take this.

BTW, a list box with over 500 items seems a little user-unfriendly ;-)

HTH,

Rob
 
J

Jessica

Thank you so much Rob I will try this when I get home tonight. I thought
that maybe what I wanted was asking too much but I guess not.

Thanks a million,
Jess
 

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

Similar Threads

help please 5
Page numbering with Merged Document and IF statements 1
run-time error 3464 2
iif functin in report 5
Help Please SUMIF question 1
Cant Seem to Nail this Lookup 9
Forms/Fill-in 0
Array question 2

Top