C
Cyberwolf
I have a module that builds a sql statement to run a select query. I am
having issues with the code that builds the In clause from the list box. All
it is placing is the comma between each item selected in the list box. I
know at one time you could only used numerics in an In statement but I
thought that after office 97 this was set to accept alpha/numerics. Here is
the code I am using
Dim varItem As Variant
Dim strSQL As String
Dim strWhere As String
Dim strWhere1 As String
strSQL = "Select * from tblSegmentOutput_Test"
strWhere = strWhere & " WHERE [QuoteNumber] = " & "'" & Me.txtQuote &
"'" & _
" AND [Revision] = " & "'" & Me.txtRevision & "'" & _
" AND [LineNumber] = " & "'" & Me.txtLine & "'"
For Each varItem In Me.Controls!txtSegments.ItemsSelected
strWhere1 = strWhere1 & Me.Controls!txtSegments.ItemData(varItem) &
", "
Next varItem
If Len(strWhere) > 0 Then
strSQL = strSQL & strWhere & " AND [SegmentName] In (" & _
Left$(strWhere1, Len(strWhere1) - 2) & ")"
End If
Here is the output from strSQL
Select * from tblSegmentOutput_Test WHERE [QuoteNumber] = 'S-18859' AND
[Revision] = '0' AND [LineNumber] = '1' AND [SegmentName] In (, , , )
In this case I had 4 items selected. I only get nulls on this line
? Me.Controls!txtSegments.ItemData(varItem)
Null
TIA
having issues with the code that builds the In clause from the list box. All
it is placing is the comma between each item selected in the list box. I
know at one time you could only used numerics in an In statement but I
thought that after office 97 this was set to accept alpha/numerics. Here is
the code I am using
Dim varItem As Variant
Dim strSQL As String
Dim strWhere As String
Dim strWhere1 As String
strSQL = "Select * from tblSegmentOutput_Test"
strWhere = strWhere & " WHERE [QuoteNumber] = " & "'" & Me.txtQuote &
"'" & _
" AND [Revision] = " & "'" & Me.txtRevision & "'" & _
" AND [LineNumber] = " & "'" & Me.txtLine & "'"
For Each varItem In Me.Controls!txtSegments.ItemsSelected
strWhere1 = strWhere1 & Me.Controls!txtSegments.ItemData(varItem) &
", "
Next varItem
If Len(strWhere) > 0 Then
strSQL = strSQL & strWhere & " AND [SegmentName] In (" & _
Left$(strWhere1, Len(strWhere1) - 2) & ")"
End If
Here is the output from strSQL
Select * from tblSegmentOutput_Test WHERE [QuoteNumber] = 'S-18859' AND
[Revision] = '0' AND [LineNumber] = '1' AND [SegmentName] In (, , , )
In this case I had 4 items selected. I only get nulls on this line
? Me.Controls!txtSegments.ItemData(varItem)
Null
TIA