Go here for reference:
http://www.access-programmers.co.uk/forums/showthread.php?t=99353
Ok, I am using this form to perform a search, but it is not working for me.
When I click the search button, my subform becomes blank. I need your help.
Here is my code:
http://www.access-programmers.co.uk/forums/showthread.php?t=99353
Ok, I am using this form to perform a search, but it is not working for me.
When I click the search button, my subform becomes blank. I need your help.
Here is my code:
Code:
Private Sub btnClear_Click()
Dim intIndex As Integer
' Clear all search items
Me.txtSearchCompany = ""
Me.txtSearchZip = ""
Me.txtSearchState = ""
Me.txtSearchDateR = ""
Me.txtSearchDateC = ""
End Sub
Private Sub btnSearch_Click()
' Update the record source
Me.subfrmAccounts.Form.RecordSource = "SELECT * FROM qryAccounts " & BuildFilter
' Requery the subform
Me.subfrmAccounts.Requery
End Sub
Private Sub Form_Load()
' Clear the search form
btnClear_Click
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
varWhere = Null ' Main filter
' Check for LIKE Company
If Me.txtSearchCompany > "" Then
varWhere = varWhere & "[Company] LIKE """ & Me.txtSearchCompany & "*"" AND "
End If
' Check for LIKE Zip Code
If Me.txtSearchZip > "" Then
varWhere = varWhere & "[Zip Code] LIKE """ & Me.txtSearchZip & "*"" AND "
End If
' Check for LIKE State
If Me.txtSearchState > "" Then
varWhere = varWhere & "[State] LIKE """ & Me.txtSearchState & "*"" AND "
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