Filter Open Report (1 Viewer)

jeffjohnson29

New member
Local time
Today, 05:07
Joined
Nov 9, 2017
Messages
8
I would like to add a button on the header of a report that will filter the text on the open report by what is in a control text box. Below is what I have tried but it is not applying the filter correctly and I am unsure of what I am doing wrong

Private Sub btnFilter_Click()

DoCmd.SetFilter , [iCloud Account] LIKE " *& Me.txtFilterTerm &* "

End Sub

Thank you ahead of time for the help!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:07
Joined
Feb 19, 2002
Messages
42,981
Where is me.txtFilterTerm coming from? You are referencing a control on the report. When you reference a control this way, it is always the current record.
 

Ranman256

Well-known member
Local time
Today, 06:07
Joined
Apr 9, 2015
Messages
4,339
you dont do it that way,
you turn on/off the filter THEN open the report.

Code:
sub btnReport_Click()

if IsNull(txtFilterTerm) then
   sFlt = ""
else
   sFlt = "[iCloud Account] LIKE  '*" & Me.txtFilterTerm & "*'"
endif

docmd.OpenReport "rpt",acViewPreview ,,sFlt
end sub
 

Users who are viewing this thread

Top Bottom