Im having serious problems getting my head around this:banghead:I want to pass a list box (which is called Pract_List) to a paramter query called testquery but for some reason it wont work. The line qdf.SQL = strSQL is comming up in the debugger could anyone help?
Private Sub Command_4_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("TESTQUERY")
For Each varItem In Me!Pract_List.ItemsSelected
strCriteria = strCriteria & "," & Me!Pract_List.ItemData(varItem) & ""
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything." _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "SELECT [Tbl GMS Assets V2 8th Nov].ID, [Tbl GMS Assets V2 8th Nov].[Asset Id], [Tbl GMS Assets V2 8th Nov].Description, [Tbl GMS Assets V2 8th Nov].Manufacturer, [Tbl GMS Assets V2 8th Nov].Model, [Tbl GMS Assets V2 8th Nov].[Serial No], [Tbl GMS Assets V2 8th Nov].[Location Details], [Tbl GMS Assets V2 8th Nov].[Asset verified], [Tbl GMS Assets V2 8th Nov].[Old asset Id], [Tbl GMS Assets V2 8th Nov].[Additional information], [Tbl GMS Assets V2 8th Nov].[PRACTICE CODE], [Tbl GMS Assets V2 8th Nov].[purchase date], [Tbl GMS Assets V2 8th Nov].[Date Asset Checked] FROM [Tbl GMS Assets V2 8th Nov]" & _
"WHERE((([Tbl GMS Assets V2 8th Nov].[PRACTICE CODE])=[Forms]![Test_Form]![Pract_List]));IN(" & strCriteria & ");"
qdf.SQL = strSQL
DoCmd.OpenQuery "TESTQUERY"
Set db = Nothing
Set qdf = Nothing
End Sub
Private Sub Command_4_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("TESTQUERY")
For Each varItem In Me!Pract_List.ItemsSelected
strCriteria = strCriteria & "," & Me!Pract_List.ItemData(varItem) & ""
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything." _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "SELECT [Tbl GMS Assets V2 8th Nov].ID, [Tbl GMS Assets V2 8th Nov].[Asset Id], [Tbl GMS Assets V2 8th Nov].Description, [Tbl GMS Assets V2 8th Nov].Manufacturer, [Tbl GMS Assets V2 8th Nov].Model, [Tbl GMS Assets V2 8th Nov].[Serial No], [Tbl GMS Assets V2 8th Nov].[Location Details], [Tbl GMS Assets V2 8th Nov].[Asset verified], [Tbl GMS Assets V2 8th Nov].[Old asset Id], [Tbl GMS Assets V2 8th Nov].[Additional information], [Tbl GMS Assets V2 8th Nov].[PRACTICE CODE], [Tbl GMS Assets V2 8th Nov].[purchase date], [Tbl GMS Assets V2 8th Nov].[Date Asset Checked] FROM [Tbl GMS Assets V2 8th Nov]" & _
"WHERE((([Tbl GMS Assets V2 8th Nov].[PRACTICE CODE])=[Forms]![Test_Form]![Pract_List]));IN(" & strCriteria & ");"
qdf.SQL = strSQL
DoCmd.OpenQuery "TESTQUERY"
Set db = Nothing
Set qdf = Nothing
End Sub