Hello,
I was wondering if anyone can tell me what's wrong with the following code. It looks right to me, but when I execute it the listbox always shows up empty. I've attached a screenshot of the underlying query containing dummy data.
Code:
Private Sub cboFilterStatus_AfterUpdate()
Me.lstBlankets.RowSource = build_SQL_query()
Me.lstBlankets.Requery
End Sub
Private Sub cboFilterType_AfterUpdate()
Me.lstBlankets.RowSource = build_SQL_query()
Me.lstBlankets.Requery
End Sub
Function build_SQL_query() As String
Dim SQL As String
' Always include the blanket name filter
SQL = "SELECT * FROM gryCurrentBlanketStatus WHERE [BlanketName] LIKE *" & [Forms]![frmBlankets]![txtFilterName] & "*"
' If the type is not null include this
If Not IsNull(Me.cboFilterType) Then
SQL = SQL & " AND [Type]='" & Me.cboFilterType & "'"
End If
' If the status is not null, filter on this
If Not IsNull(Me.cboFilterStatus) Then
SQL = SQL & " AND [LastOfStatus1]=" & Me.cboFilterStatus
End If
build_SQL_query = SQL
End Function