Search box (1 Viewer)

khurram7x

Registered User.
Local time
Today, 08:50
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: 43

Minty

AWF VIP
Local time
Today, 04:50
Joined
Jul 26, 2013
Messages
10,373
The wild cards need to be inside your quotes;

LIKE '*" & Me.txtSearchCriteria & "*' "
 

khurram7x

Registered User.
Local time
Today, 08:50
Joined
Mar 4, 2015
Messages
226
Thank you, worked.
Now how to filter only results matching search criteria please?

Regards,
K
 

Minty

AWF VIP
Local time
Today, 04:50
Joined
Jul 26, 2013
Messages
10,373
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

Top Bottom