Solved Unable to Filter Query (1 Viewer)

abdullahkhan

Member
Local time
Today, 12:37
Joined
Apr 14, 2020
Messages
274
Hello,

I am trying to filter a query using a textbox on a loaded form and I am using following SQL but it is not working.

SQL:
SELECT tblReports.*, tblReports.ReportTitle
FROM tblReports
WHERE (((tblReports.ReportTitle) Like '* & Forms![frmSearchReport]![ReportTitle] & *'));

I am using this query on a subform and using me.SubFormControlName.requery in on change and after update event to filter the results. I want to implement search option so that user can search any text in the report title. Please help.

Best Regards,
Abdullah
 

arnelgp

error reading drive A:
Local time
Today, 15:37
Joined
May 7, 2009
Messages
12,021
Code:
...
...
WHERE (((tblReports.ReportTitle) Like "*" & Forms![frmSearchReport]![ReportTitle] & "*"));
 

abdullahkhan

Member
Local time
Today, 12:37
Joined
Apr 14, 2020
Messages
274
Code:
...
...
WHERE (((tblReports.ReportTitle) Like "*" & Forms![frmSearchReport]![ReportTitle] & "*"));
Thanks. It works. But it work only with after update event i.e. when I leave the text box or press enter key. Why is it not working with on change event so that it searched as I type. I used the same code in both events i.e me.SubFormControlName.requery

PS. I'm not saying it's with the SQL because query work fine but event is not working.
 

arnelgp

error reading drive A:
Local time
Today, 15:37
Joined
May 7, 2009
Messages
12,021
save the Text property to variable:
Code:
Dim strText As String
strText = Me![ReportTitle].Text
...
...
WHERE (((tblReports.ReportTitle) Like "*" & strText & "*"));
 

abdullahkhan

Member
Local time
Today, 12:37
Joined
Apr 14, 2020
Messages
274
save the Text property to variable:
Code:
Dim strText As String
strText = Me![ReportTitle].Text
...
...
WHERE (((tblReports.ReportTitle) Like "*" & strText & "*"));
Thanks for reply. Since I'm using query design to make the query and criteria (not VBA) so I can't use dim method to define variable.
 

Users who are viewing this thread

Top Bottom