Multi Keyword Search from List Box

  • Thread starter Chris via AccessMonster.com
  • Start date
C

Chris via AccessMonster.com

I have a form with a list boxes, a text box and two button in the middle to
add or remove keywords from the list box to the text box.

The list box lists all the possible skills. The user highlights a skill and
clicks on the button to add that skill to the Text box. They can select up
to 3-skills . Once the skills are in the Text box, I need to click a button
that would filter the form to show me all the employees with those skills.

I have the two boxes working so that when I click on the button in the
middle of the two boxes, I can add keywords from the list box to the Text box.
but I don't know how to filter the form based on the selections in the text
box.

Thanks for your help...

Chris
 
J

Jeff L

Here is something I have used:

Here is something I have used.

Dim FilterString As String, Position As Integer, DescriptionFilter As
String, HoldDescriptionFilter As String


If Not IsNull(Me.FilterDescription) Then
HoldDescriptionFilter = Me.FilterDescription
Position = InStr(1, HoldDescriptionFilter, ",",
vbTextCompare)
If Position > 0 Then 'There is more than one word to look
for in the description
Do Until Position = 0
DescriptionFilter = IIf(DescriptionFilter = "",
"Description like '*" & _
Left(HoldDescriptionFilter, Position - 1) & "*' ",
DescriptionFilter & "Or Description like '*" & _
Left(HoldDescriptionFilter, Position - 1) & "*' ")
HoldDescriptionFilter = Trim(Mid(HoldDescriptionFilter,
Position + 1))
Position = InStr(1, ",", HoldDescriptionFilter,
vbTextCompare)
Loop
DescriptionFilter = DescriptionFilter & "Or Description
like '*" & HoldDescriptionFilter & "%' "
FilterString = IIf(FilterString = "", DescriptionFilter, _
FilterString & "And (" &
DescriptionFilter & ")")
Else


FilterString = IIf(FilterString = "", "Description Like '*"

& Me.FilterDescription & "*'", _
FilterString & "And Description Like '*" &
Me.FilterDescription & "*'")
End IF
Me.Filter = FilterString
Me.FilterOn = True


Else
Me.FilterOn = False
End IF

You may need to modify it a little to fit what you're doing but it
should do the trick.
 
G

Guest

The text box you are using to hold the selections from the list box is a
waste of time. It is actually easier to get the values directly from the
list box. You will want to use a multi select list box.


Private Function BuildWhereCondition(strControl As String) As String
'Set up the WhereCondition Argument for the reports
Dim varItem As Variant
Dim strWhere As String
Dim ctl As Control

Set ctl = Me.Controls(strControl)

Select Case ctl.ItemsSelected.Count
Case 0 'Include All
strWhere = ""
Case 1 'Only One Selected
strWhere = "= '" & _
ctl.ItemData(ctl.ItemsSelected(0)) & "'"
Case Else 'Multiple Selection
strWhere = " IN ("

With ctl
For Each varItem In .ItemsSelected
strWhere = strWhere & "'" & .ItemData(varItem) & "', "
Next varItem
End With
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
End Select

If Len(strWhere) > 0 Then
strWhere = "[FieldToFilterOn] " & STRWhere
Me.Filter = strWhere
Me.FilterOn = True
End If
 

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