kristi1023
Programmer
I am using a Multi-Select List box that searches Skills and it works great. However, I now have to add Skill Level to the list box and perform the search based on 2 columns (Skill and Skill Level ID). Here is my code:
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim varSkill As Variant
Dim varItem As Variant
Dim intIndex As Integer
Dim varSkillLevel As Variant
varWhere = Null ' Main filter
varSkill = Null ' Subfilter used for Skills
varSkillLevel = Null
' Check for Skills in multiselect list
For Each varItem In Me.lstSkills.ItemsSelected
varSkill = varSkill & "[Skill] = """ & _
Me.lstSkills.ItemData(varItem) & """ OR "
varSkillLevel = varSkillLevel & """" & Me.lstSkills.Column(2, varItem) & """, "
[highlight #FF99FF]Here I am checking for Skill Level ID (Column2)[/highlight]
Next
' Test to see if we have subfilter for Skills...
If IsNull(varSkill) Then
' do nothing
Else
' strip off last "OR" in the filter
If Right(varSkill, 4) = " OR " Then
varSkill = Left(varSkill, Len(varSkill) - 4)
End If
' Add some parentheses around the subfilter
varWhere = varWhere & "( " & varSkill & " )"
[highlight #FF99FF]I think I need to build the Skill Level ID into the filter here? Any ideas would be great![/highlight]
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
End Function
Thanks..Kristi..
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim varSkill As Variant
Dim varItem As Variant
Dim intIndex As Integer
Dim varSkillLevel As Variant
varWhere = Null ' Main filter
varSkill = Null ' Subfilter used for Skills
varSkillLevel = Null
' Check for Skills in multiselect list
For Each varItem In Me.lstSkills.ItemsSelected
varSkill = varSkill & "[Skill] = """ & _
Me.lstSkills.ItemData(varItem) & """ OR "
varSkillLevel = varSkillLevel & """" & Me.lstSkills.Column(2, varItem) & """, "
[highlight #FF99FF]Here I am checking for Skill Level ID (Column2)[/highlight]
Next
' Test to see if we have subfilter for Skills...
If IsNull(varSkill) Then
' do nothing
Else
' strip off last "OR" in the filter
If Right(varSkill, 4) = " OR " Then
varSkill = Left(varSkill, Len(varSkill) - 4)
End If
' Add some parentheses around the subfilter
varWhere = varWhere & "( " & varSkill & " )"
[highlight #FF99FF]I think I need to build the Skill Level ID into the filter here? Any ideas would be great![/highlight]
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
End Function
Thanks..Kristi..