Hayley Baxter
Registered User.
- Local time
- Today, 07:50
- Joined
- Dec 11, 2001
- Messages
- 1,607
Hi All
Wondering if any of you kind people can help me out with this. I have a multiselect listbox of companies so I need to be able to choose the selection(s) to then email or print etc. I have a textbox on the form as well which puts in the selection(s) made by the user. This part seems to be working ok.
However I do have a problem with the code in that it keeps throwing up error 3075 "Syntax error(missing operator) in query expression. If I could resolve this part of the coding all should work well. Anyone any ideas?
here is the code:
Private Sub Search_Click()
Dim vItm As Variant
Dim stWhat As String
Dim stCriteria As String
Dim stSQL As String
Dim loqd As QueryDef
stWhat = "": stCriteria = ","
For Each vItm In Me!LstBoxCompany.ItemsSelected
stWhat = stWhat & Me!LstBoxCompany.ItemData(vItm)
stWhat = stWhat & stCriteria
Next vItm
Me!txtCriteria = CStr(left$(stWhat, Len(stWhat) - Len(stCriteria)))
Set loqd = CurrentDb.QueryDefs("qryMultiSelect")
stSQL = "SELECT CompanyID, Company Name "
stSQL = stSQL & "Company Name FROM qrycompdet WHERE CompanyID"
stSQL = stSQL & " IN (" & Me!txtCriteria & ")"
loqd.SQL = stSQL
loqd.Close
DoCmd.OpenQuery "qryMultiSelect"
Any help with this greatly appreciated.
Many thanks
Hayley
Wondering if any of you kind people can help me out with this. I have a multiselect listbox of companies so I need to be able to choose the selection(s) to then email or print etc. I have a textbox on the form as well which puts in the selection(s) made by the user. This part seems to be working ok.
However I do have a problem with the code in that it keeps throwing up error 3075 "Syntax error(missing operator) in query expression. If I could resolve this part of the coding all should work well. Anyone any ideas?
here is the code:
Private Sub Search_Click()
Dim vItm As Variant
Dim stWhat As String
Dim stCriteria As String
Dim stSQL As String
Dim loqd As QueryDef
stWhat = "": stCriteria = ","
For Each vItm In Me!LstBoxCompany.ItemsSelected
stWhat = stWhat & Me!LstBoxCompany.ItemData(vItm)
stWhat = stWhat & stCriteria
Next vItm
Me!txtCriteria = CStr(left$(stWhat, Len(stWhat) - Len(stCriteria)))
Set loqd = CurrentDb.QueryDefs("qryMultiSelect")
stSQL = "SELECT CompanyID, Company Name "
stSQL = stSQL & "Company Name FROM qrycompdet WHERE CompanyID"
stSQL = stSQL & " IN (" & Me!txtCriteria & ")"
loqd.SQL = stSQL
loqd.Close
DoCmd.OpenQuery "qryMultiSelect"
Any help with this greatly appreciated.
Many thanks
Hayley