View Full Version : Trying to do a filter


twinytwo
11-22-2008, 02:19 AM
I have a "filter" on one of my forms that is ment to filter the records based on what is seleted in several combo boxes... i have the subform created the code behind the serach button is

Private Sub Command15_Click()
Dim strSQL As String, intCounter As Integer
'Build SQL String
For intCounter = 1 To 6
If Me("Filter" & intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
End If
Next
If strSQL <> "" Then
'Strip Last " And "
strSQL = Left(strSQL, (Len(strSQL) - 5))
'Set the Filter property
Me.Stock__subform.Form.Filter = strSQL
Me.Stock__subform.Form.FilterOn = True
Else
Me.Stock__subform.Form.FilterOn = False
End If
End Sub
Private Sub Command16_Click()
Me.Stock__subform.Form.FilterOn = False
Filter1.Value = ""
Filter2.Value = ""
Filter3.Value = ""
Filter4.Value = ""
Filter5.Value = ""
Filter6.Value = ""
End Sub

Now the problem is that when i hit the button the subform comes up as blank instead of displaying the records..... any idea where im going wrong?/

jal
11-22-2008, 06:50 AM
To debug, what I do is set a breakpoint, and type into the Immediate Window


? strSQL


Maybe let us know the output?

jal
11-22-2008, 06:51 AM
Also, you may need to reset the subform's query-source. Like this:

Dim qry As QueryDef
Set qry = CurrentDb.QueryDefs("qryCust")
qry.SQL = "Select top 5 from customers" ' <-- change the query here.
Me.subformCustomers.SourceObject = "Query.qryCust"
Me.subformCustomers.Requery