search query construction

F

freelancer

Although I’ve been using access for a number of years and have built a number
of databases I have not as yet been able to interrogate a query from a form.
I would like to be able to do this.
Essentially I want to create a form which has an empty ‘parameter query’
type box embedded, a drop-down-list of field which can be searched, and a
‘go’ button. The user will then be able to enter a search term, select the
field which he want’s to search and then ‘go’ to get the results (shown on a
‘continuous forms’ form).
Could somebody please advise a way I can do this?

Any responses will be greatly appreciated
 
D

Dennis

Create your combo box with row source type set to field list and row source
set to your table and then have a text box where you can enter the value. The
code behind the Go button should then build your criteria simiar to this

Dim strCriteria As String

strCriteria = Me.cmbField & " = '" & Me.txtValue & "'"
DoCmd.OpenForm "Your Form Name", , , strCriteria
 
F

freelancer

Thanks for the advice,

Unfortunately this is not working: I’ve changed the "Your Form Name" to the
name of both the form I would like to open with results as well as the form I
am running the searching from and on both searches I am sent to the VB
editor. At both attempts the ‘Me.cmbField’ section of text is highlighted.
I have tried changing this to the field name I am searching but still with no
results.

Any other suggestions? Once again thanks for the help, it’s appreciated.
 
D

Dennis

Your Form Name is the form that if opened on its own would show all your
records.
cmbField is the name of your combo box containing the field list names.
txtValue is the field holding the criteria to search for.
Make sure you have included the apostrophes as in my code.
I have tested the code I provided and it works OK.
 

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