Hi
I am trying to open a recordset based on a query, but using an SQL statement to only retrieve certain records. I am using VBA to create a string with the criteria from a list box. When the code runs, the recordset contains all the records from the "parts" query instead of just the selected records. Here is the part of code with the problem:
strselcabs = ""
For Each selcab In Me!cablst.ItemsSelected 'creates a string criteria
cab = Me!cablst.ItemData(selcab)
strselcabs = strselcabs & Chr(34) & cab & Chr(34) & " OR "
Next
strselcabs = Left(strselcabs, (Len(strselcabs) - 4)) 'strips the last " OR " from the string criteria
Set rstcabpts = dbs.OpenRecordset("SELECT * FROM parts WHERE [CABLE ID]= " & strselcabs, dbOpenDynaset)
I am not too familiar with SQL, so imagine the problem lies there. Any help appreciated.
Cheers,
Paul.
I am trying to open a recordset based on a query, but using an SQL statement to only retrieve certain records. I am using VBA to create a string with the criteria from a list box. When the code runs, the recordset contains all the records from the "parts" query instead of just the selected records. Here is the part of code with the problem:
strselcabs = ""
For Each selcab In Me!cablst.ItemsSelected 'creates a string criteria
cab = Me!cablst.ItemData(selcab)
strselcabs = strselcabs & Chr(34) & cab & Chr(34) & " OR "
Next
strselcabs = Left(strselcabs, (Len(strselcabs) - 4)) 'strips the last " OR " from the string criteria
Set rstcabpts = dbs.OpenRecordset("SELECT * FROM parts WHERE [CABLE ID]= " & strselcabs, dbOpenDynaset)
I am not too familiar with SQL, so imagine the problem lies there. Any help appreciated.
Cheers,
Paul.