Hi: I have been looking for VBA Code to make a search command button. Could anyone help with this please? Thank you. I only joined this site a few days ago and I have learned alot already. Thank you!
Hi: I have been looking for VBA Code to make a search command button. Could anyone help with this please? Thank you. I only joined this site a few days ago and I have learned alot already. Thank you!
A very broad question and the answer very much depends on what you are searching for and where and how you want to search. Assuming your button is on a form which has the recordset you want to search the principle is
me.filter="searchcriteria"
me.filteron=true
to build your search criteria you might have
searchcriteria="[customerName] like '*" & txtCustomerName & "*'"
or
searchcriteria="[Amount]=" & txtAmount
where tctCustomerName and txtAmount are the names of unbound controls on your form
to combine them you would have
searchcriteria="[customerName] like '*" & txtCustomerName & "*' AND [Amount]=" & txtAmount
Since you are new to this, to practice and experiment I would set up query in the query designer and set criteria to 'find' the records you want. When you have it working, look at the SQL view for what appears after the WHERE keyword - note the use of brackets and quotation marks, this will be how you need to construct your search criteria string
Thank you!