mark curtis
Registered User.
- Local time
- Today, 20:37
- Joined
- Oct 9, 2000
- Messages
- 457
Dear all,
I am really stumped and need the help of VB guru's.
I have a query that uses other queries and tables in it's make up. The criteria at present for the query is in the department field "=forms![frmreports]![txtDepartment]" which is the content of a text box on a form that is selected from a combo box.
What I want to do is replace the combo box on the form with a multi select list box and have the query department field criteria be the selection, such as DeptA or DeptB or DeptC.
I have tried to use the following code but I am getting no where.
Dim Q As QueryDef, DB As Database
Dim Criteria As String
Dim ctl As Control
Dim Itm As Variant
' Build a list of the selections.
Set ctl = Me![List0]
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & OR & Chr(34) & ctl.ItemData(Itm)& Chr(34)
End If
Next Itm
If Len(Criteria) = 0 Then
Itm = MsgBox("You must select one or more items in the" & _
" list box!", 0, "No Selection Made")
Exit Sub
End If
' Modify the Query.
Set DB = CurrentDb()
Set Q = DB.QueryDefs("MY Query Name")
Set Dept Criteria = Criteria
End Sub
MY problem is that I need to return the criteria in DeptA OR DeptB...... using OR.
All I want to do is pass a couple of Department names to the department field criteria.
Thanks
Mark
I am really stumped and need the help of VB guru's.
I have a query that uses other queries and tables in it's make up. The criteria at present for the query is in the department field "=forms![frmreports]![txtDepartment]" which is the content of a text box on a form that is selected from a combo box.
What I want to do is replace the combo box on the form with a multi select list box and have the query department field criteria be the selection, such as DeptA or DeptB or DeptC.
I have tried to use the following code but I am getting no where.
Dim Q As QueryDef, DB As Database
Dim Criteria As String
Dim ctl As Control
Dim Itm As Variant
' Build a list of the selections.
Set ctl = Me![List0]
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & OR & Chr(34) & ctl.ItemData(Itm)& Chr(34)
End If
Next Itm
If Len(Criteria) = 0 Then
Itm = MsgBox("You must select one or more items in the" & _
" list box!", 0, "No Selection Made")
Exit Sub
End If
' Modify the Query.
Set DB = CurrentDb()
Set Q = DB.QueryDefs("MY Query Name")
Set Dept Criteria = Criteria
End Sub
MY problem is that I need to return the criteria in DeptA OR DeptB...... using OR.
All I want to do is pass a couple of Department names to the department field criteria.
Thanks
Mark