G
Guest
Thanks for taking the time to read my question.
I want to filter this query by the values in my single column list box. I
made this function to create the string, but the query doesn't like it. If I
paste the string that the function returns into the criteria line the query
works.
What am I doing wrong?
Thanks,
Brad
SQL:
SELECT tblPeripheral.Type, tblPeripheral.Location, tblPeripheral.[Serial
Number], tblPeripheral.Model, tblPeripheral.Brand, tblPeripheral.[Model 2],
ExportPeripheralInfo() AS Expr1
FROM tblPeripheral
WHERE (((tblPeripheral.Type)=ExportPeripheralInfo()));
Function:
Function ExportPeripheralInfo() As String
Dim FilterCriteria As String
Dim ctl As Control
Dim c As Variant
Set ctl = Forms![frmReportCenter]![lstSiteOrType]
For Each c In ctl.ItemsSelected
If FilterCriteria = "" Then
FilterCriteria = """" & ctl.ItemData(c) & """"
Else
FilterCriteria = """" & ctl.ItemData(c) & """" & " Or Like " &
FilterCriteria
End If
Next c
ExportPeripheralInfo = "Like " & FilterCriteria
'Debug.Print ExportPeripheralInfo
End Function
I want to filter this query by the values in my single column list box. I
made this function to create the string, but the query doesn't like it. If I
paste the string that the function returns into the criteria line the query
works.
What am I doing wrong?
Thanks,
Brad
SQL:
SELECT tblPeripheral.Type, tblPeripheral.Location, tblPeripheral.[Serial
Number], tblPeripheral.Model, tblPeripheral.Brand, tblPeripheral.[Model 2],
ExportPeripheralInfo() AS Expr1
FROM tblPeripheral
WHERE (((tblPeripheral.Type)=ExportPeripheralInfo()));
Function:
Function ExportPeripheralInfo() As String
Dim FilterCriteria As String
Dim ctl As Control
Dim c As Variant
Set ctl = Forms![frmReportCenter]![lstSiteOrType]
For Each c In ctl.ItemsSelected
If FilterCriteria = "" Then
FilterCriteria = """" & ctl.ItemData(c) & """"
Else
FilterCriteria = """" & ctl.ItemData(c) & """" & " Or Like " &
FilterCriteria
End If
Next c
ExportPeripheralInfo = "Like " & FilterCriteria
'Debug.Print ExportPeripheralInfo
End Function