Search box

khurram7x

Registered User.
Local time
Today, 16:38
Joined
Mar 4, 2015
Messages
226
Hi,

I'm looking to add search functionality on form using a text box and button, attaching screenshot. I'm using DoCmd.SearchForRecord command for that and it works fine if I used it to search, but when I try to use '* Criteria *' wildcard it doesn't search as expected and stays on the same record. I think SearchForRecord is only considering * and not rest of the criteria. Is I'm using the correct syntax please?? i.e. DoCmd.SearchForRecord , , , "Job_Description LIKE * '" & Me.txtSearchCriteria & "' * "

Additionally it will be preferable that when search results on the form will be filtered as search results only. How could I achieve that please??

Thanks,
K
 

Attachments

  • Search.JPG
    Search.JPG
    57.8 KB · Views: 92
The wild cards need to be inside your quotes;

LIKE '*" & Me.txtSearchCriteria & "*' "
 
Thank you, worked.
Now how to filter only results matching search criteria please?

Regards,
K
 
In VBA set the form filter to your search criteria;

Code:
Me.Filter = "[Job_Description] LIKE  '*" & Me.txtSearchCriteria & "*'"
Me.FilterOn = True

You might want to add a reset button to clear the filter, depending on the use of the form.
 

Users who are viewing this thread

Back
Top Bottom