In the Function BuildFilter, this code is invalid:
' If varWhere.NoMatch Then
' MsgBox "Record not found"
' End If
varWhere is a variant variable. It does not have a NoMatch property. It just holds data, so the msgbox line would never execute.
Looking at the code:
Code:
Private Sub btnSearch_Click()
' Update the record source
Me.sfrmform.SearchForm.RecordSource = "SELECT * FROM qrySearch " & BuildFilter
' Requery the subform
Me.sfrmform.SearchForm.Requery
End Sub
You could use
Code:
Private Sub btnSearch_Click()
Dim MyFilter as Variant
MyFilter = BuildFilter
' Update the record source
Me.sfrmform.SearchForm.RecordSource = "SELECT * FROM qrySearch " & MyFilter
' Requery the subform
Me.sfrmform.SearchForm.Requery
End Sub
Now you can see the Filter property returned by the function (if you single step thru the code). But that won't tell you if the SQL returns records.
I am confused on the syntax of the lines that set the form record source and the re-query. I can't tell which is the main form (name) and which is the subform.
Is "sfrmform" the subform name?
This is the reference I use when trying to check form/subform properties (I have it printed out - it is available in DOC format to download)
Refer to Form and Subform properties and controls
http://access.mvps.org/access/forms/frm0031.htm
You could check the recordsetclone property of the subform to see if there are/were records returned after the requery. Then use the message boxif no records are in the subform.