Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA conditions

Status
Not open for further replies.

ctrlsme

MIS
Apr 9, 2010
1
US
Hi,

The following code loops through all items selected by the end user in a list box and then builds a report based on those selected items. I would like put in a condition that says "if the selected item = Order lead time, then open an alternative report." how would I go about writing this in?
I started witht he following but it does not work.

Example of what I tried:
If (varItem) = "Order lead time"
DoCmd.OpenReport "rpt-Backorders", acViewPreview


Example of the code:

Private Sub cmdPreview_Click()
On Error GoTo Err_Handler
Dim varItem As Variant
Dim strWhere As String
Dim strDescrip As String
Dim lngLen As Long
Dim strDelim As String
Dim strDoc As String

strDelim = """"
strDoc = "rpt-OrderIssues"

With Me.lstCategory
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then

strWhere = strWhere & strDelim & .ItemData(varItem) & strDelim & ","
strDescrip = strDescrip & """" & .Column(1, varItem) & """, "
End If
Next
End With
 
the variable varItem contains the listnumber of the selected item in the list

so if u are certain that the rowsource of your listbox is always the same and for example "Order lead time" is always the first selection in the listbox u can work like this


if varitem = 1 then DoCmd.OpenReport "rpt-Backorders", acViewPreview

if your listbox rowsource is build by code or linked to a table/query : take a look at the ItemData function in your VBeditor help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top