nikademous
Technical User
Hello, I needed to add to my search form the ability to search from a multi select list box for data in a numeric field (RuleOfConductNum) from my table (tbl_ContactRecord). The data in the field is saved from a multi list box with a comma between each number such as 2,6,3 or 7,11.
I want to be able to search from my multi listbox (lstFindContactNum). So if I selected 2 and 3 it would bring up the records that has a 2 and three in the (RuleOfConductNum) field. Below is the already in place search that I use.
To call the function I use:
I want to be able to search from my multi listbox (lstFindContactNum). So if I selected 2 and 3 it would bring up the records that has a 2 and three in the (RuleOfConductNum) field. Below is the already in place search that I use.
To call the function I use:
Code:
Me.Form.RecordSource = "SELECT * FROM qry_SearchEntries " & BuildFilter
Me.Requery
Code:
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim intIndex As Integer
varWhere = Null
If Not IsNull(Me.cboEmployeeName) And Me.cboEmployeeName <> 0 Then
' If Not IsNull(Me.cboEmployeeName) Then
' varWhere = varWhere & "([EmployeeName] = """ & Me.cboEmployeeName & """) AND "
varWhere = varWhere & "([EmployeeID] = " & Me.cboEmployeeName & ") AND "
End If
'Another text field example. Use Like to find anywhere in the field.
If Not IsNull(Me.txtPhraseContains) Then
varWhere = varWhere & "([ReasonForContact] Like ""*" & Me.txtPhraseContains & "*"") AND "
End If
If Not IsNull(Me.cboYear) Then
varWhere = varWhere & "Year([DateOfIncident]) = " & Me.cboYear & " AND "
End If
If Not IsNull(Me.optContactGroup) Then
If Me.optContactGroup.Value = 1 Then
varWhere = varWhere & "([Contact] = " & Me.optContactGroup & ") AND "
Else
varWhere = varWhere & "([Contact] = " & Me.optContactGroup & ") AND "
End If
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
' strip off last "AND" in the filter
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
' Debug.Print varWhere
End Function