coding to run search for info from table using textbox in form

N

Noemi

I would like some help in writing a code for a button on a form that when
clicked a search is run to find the records with the criteria nominated in
the text boxes.

I am new at this and am not sure how to begin as I have never done codes in
Access only in Excel which is different.

Any help would be appreciated.

Thanks
 
R

Rob Oldfield

There are various ways of doing it, and the best way is really dependent
upon what you then want to do with the result of the search. One example
though... suppose that you have your form with a button and a textbox (which
I'll call txtLocationToFind) and you want to open a form only showing the
records where the location is what you enter in the textbox. You would just
need to set yourself up another form showing *all* records (which I'll call
SearchOutput). Then the code behind your button could just do this...

'crit used to store criteria to open the form with
dim crit as string
crit="[Location]='"+me.txtLocationToFind+"'"
'open the form specifying the criteria to use
docmd.openform "SearchOutput",,,crit

The fun with the speech marks is necessary because I'm assuming that the
Location field would be text... where the finished criterion would need to
be something like [Location]='London' If it's a number field then they're
not necessary.

You might need to repost and be a bit more specific about what it is you're
trying to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top