search form search button

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » Search form with search button

Search form with search button

resolvedResolved · Urgent Priority · Version 2000

Gary has attended:
Access VBA course
Excel VBA Advanced course

Search form with search button

Good morning,

I am currently trying to design a search form from the DATA table that when information is typed into the necessary fields and the search button is clicked it displays all the results for that search.

The four fields that I need are:

Surname
Forename
Birth Date
Offence Date

I have tried queries and VBA (also SQL) and for some reason it doesn't work. Could you help with some code??

Could you send to me ASAP as I need to get this completed for a project that I am working on.

Thanks,

Gary

RE: Search form with search button

Hi Gary

Thanks for the question

In general, you would first need to give your text boxes meaningful names.

Your code would then;

Declare string variables for Surname and Forename, and date variables for Offence Date and Birth Date.

You would then pass the values in the text boxes to the relevant variables. Note that all values in text boxes are text strings so you would have to use the cdate function to convert the date text box values into daye variables.

e.g.

dteOffDate = cdate(me.offdate.value)


finally you would create an SQL string with the variables embedded, this would look some thing like this;

"SELECT * FROM DATA WHERE Surname = & """ & strSurname & """ & " AND Forename" = & """ & strForename & """ & " AND Bdate"= "#" & dteBDate & "#" &" And OffenceDate" = " & "#" & dteOffDate & "#""


Finally, you would use thsi to open a DAO Recordset. This record set would then contain the data required

Hope this helps

Regards
Stephen

RE: Search form with search button

Stephen,

Thanks alot. I actually managed to code this but I also found a way of using a query, macro and form to search the table and then I also include a Clear Form button with VBA attached.

This is another useful way. I have also been using the code that you taught me a couple of weeks ago to develop my Excel sheets and make them more dynamic.

Really enjoyed your course, it was very informative and built on the knowledge that I had acquired on the Access VBA course. Good job my friend and I hope you are well.

Thanks again,

Gary

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Access tip:

Copy a Previous Record's Values to a New Record

If you often enter the same value in one field of a table, there are two methods to save re-typing the data.

1. Use Ctrl+' (apostrophe) to repeat the value input in the previous record.

2. Change the field's DefaultValue property in Design View to the most commonly used value.

View all Access hints and tips


Server loaded in 0.08 secs.