case statement question please help

  • Thread starter Thread starter David M. Fizer
  • Start date Start date
D

David M. Fizer

Can someone please tell me what this means. I have used it in a old
database but since then have change the name of my tables and forms and am
not sure what to change in this case statement to get it to work.

Private Sub Preview_Click()
0 Dim varSelectedUPC As Variant
Dim StrUPC As String

For Each varSelectedUPC In UPC.ItemsSelected
StrUPC = UPC.ItemData(varSelectedUPC)
Select Case StrUPC
Case "39000 48164"
DoCmd.OpenReport "rptNestle T-Wing", acViewPreview, , "UPC = '"
& StrUPC & "'"
End Select

Next varSelectedUPC

End Sub


Thank you in advance,
David
 
Pretty difficult for us to advise you without any idea of what you're trying
to do... <g>

The code you're posting assumes that there's a multiselect listbox named UPC
on your form. It loops through all of the selected entries in the listbox,
and if the "39000 48164" has been selected, it opens report "rptNestle
T-Wing", passing it that UPC code.

As long as you still have the multiselect listbox with that name (and it
works...), you shouldn't need to make any changes.
 
Thank you Doug for your reply you are absolutltely right that is the basis
of that statement. The problem I am having is when I select the UPC from
the list and click the preview button I get a parameter box asking to
enter a UPC with a text box, after I click Ok I get another parameter box
that just says UPC with a text box. I checked the name of the list box and
its still named UPC and the row source is a field in a table. Is there
anything else that I'm missing and could do. Thanks againg Doug.



David
 
What you're describing implies that the field name has been changed from UPC
to something else in the table or query that makes up the RecordSource for
the report.
 
That is true I renamed the field to strProductID my problem is that when
this statement worked my table, field, form, and list box were all named
UPC and now I am not sure what to change in the statement.

TIA
David
 
If the field in the query that's the recordsource for your report is named
strProductID, that's what you need in that 4th parameter:

DoCmd.OpenReport "rptNestle T-Wing", acViewPreview, , "strProductID = '" &
StrUPC & "'"

BTW, you're trimming too much from your messages. It's a real pain to have
to find your previous posts so that I can give you a complete answer!
 
Thank you Doug that worked Great. I'm sorry for cutting out my original
post from my reply. I now know not to thanks again.


David
 
Back
Top