D
dreamsoul620 via AccessMonster.com
Hi all,
I have two queries with parameters that I would like to run at one time.
These generate reports that are automatically exported into excel with the
click of a button. This works fine. Instead of the user having to type the
parameters for the queries twice, I am using a form to allow them to choose
their specifications. Two parameters are populated using combo boxes. The
third has to be a list box to provide for multiple selections. I found the
code below but cannot get it to work. Perhaps I'm not using it correctly.
I placed my form's name (percent_selection) after Form! and my list box name
(depart) after frm!
I keep getting an error stating that Percent_selection is not a valid field.
Is something other than the form name supposed to go after Form!? Also,
where does this code go so that I can use in as my parameter in both queries?
Any help is greatly appreciated.
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Dim strWhere As String
Set frm = Form!frmMyForm
Set ctl = frm!lbMultiSelectListbox
strSQL = "Select * from Employees"
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ", "
Next varItem
If Len(strWhere) > 0 The
strSQL= strSQL & " where [EmpID] In (" & _
left$(strSQL,len(strSQL)-2)) & ")"
End If
I have two queries with parameters that I would like to run at one time.
These generate reports that are automatically exported into excel with the
click of a button. This works fine. Instead of the user having to type the
parameters for the queries twice, I am using a form to allow them to choose
their specifications. Two parameters are populated using combo boxes. The
third has to be a list box to provide for multiple selections. I found the
code below but cannot get it to work. Perhaps I'm not using it correctly.
I placed my form's name (percent_selection) after Form! and my list box name
(depart) after frm!
I keep getting an error stating that Percent_selection is not a valid field.
Is something other than the form name supposed to go after Form!? Also,
where does this code go so that I can use in as my parameter in both queries?
Any help is greatly appreciated.
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Dim strWhere As String
Set frm = Form!frmMyForm
Set ctl = frm!lbMultiSelectListbox
strSQL = "Select * from Employees"
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ", "
Next varItem
If Len(strWhere) > 0 The
strSQL= strSQL & " where [EmpID] In (" & _
left$(strSQL,len(strSQL)-2)) & ")"
End If