WhereCondition

B

Bob Quintal

=?Utf-8?B?cG9tcGV5amlt?= <[email protected]>
wrote in
Hi all
I recently sent in a post asking about retrieving data from a
listbox on a search form and opening the main form showing
only the records selected from the listbox. Ken Sheridan was
kind enough to send me this bit of code:
Dim varItem As Variant
Dim strEmployeeIDList As String
Dim strCriteria As String
Dim ctrl As Control

Set ctrl = Me.lstEmployees

If ctrl.ItemsSelected.Count > 0 Then
For Each varItem In ctrl.ItemsSelected
strEmployeeIDList = strEmployeeIDList & "," &
ctrl.ItemData(varItem)
Next varItem

' remove leading comma
strEmployeeIDList = Mid(strEmployeeIDList, 2)

strCriteria = "[EmployeeID] In(" & strEmployeeIDList &
")" DoCmd.OpenForm "frmMain",
WhereCondition:=strCriteria
Else
MsgBox "No Employees Selected", vbInformation,
"Warning"
End If

Now, for the most part this code works great, but on the line:
DoCmd.OpenForm "frmMain", WhereCondition:=strCriteria
I have to admit I haven't got a clue what the WhereConditon
should be. Am I being a bit of a dipstick here and it's
something really simple. Can anyone give me an idea what I
have to put please. cheers
Jim

the line
strCriteria = "[EmployeeID] In(" & strEmployeeIDList & ")"
already puts what's required.
stremployeeIDlist should just look like 12345,34567,44444 (for 3
employee ids selected).
 
G

Guest

Hi all
I recently sent in a post asking about retrieving data from a listbox on a
search form and opening the main form showing only the records selected from
the listbox. Ken Sheridan was kind enough to send me this bit of code:
Dim varItem As Variant
Dim strEmployeeIDList As String
Dim strCriteria As String
Dim ctrl As Control

Set ctrl = Me.lstEmployees

If ctrl.ItemsSelected.Count > 0 Then
For Each varItem In ctrl.ItemsSelected
strEmployeeIDList = strEmployeeIDList & "," &
ctrl.ItemData(varItem)
Next varItem

' remove leading comma
strEmployeeIDList = Mid(strEmployeeIDList, 2)

strCriteria = "[EmployeeID] In(" & strEmployeeIDList & ")"
DoCmd.OpenForm "frmMain", WhereCondition:=strCriteria
Else
MsgBox "No Employees Selected", vbInformation, "Warning"
End If

Now, for the most part this code works great, but on the line:
DoCmd.OpenForm "frmMain", WhereCondition:=strCriteria
I have to admit I haven't got a clue what the WhereConditon should be.
Am I being a bit of a dipstick here and it's something really simple.
Can anyone give me an idea what I have to put please.
cheers
Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top