Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RE: Run a Query through a form

0 views
Skip to first unread message

Ofer

unread,
Nov 3, 2005, 12:05:04 PM11/3/05
to
You can try this

Create an empty query, for this example will call it MyQuery
Create a button on the form to assign SQL to this Query that include a
filter from a field in the form.

Use the code to change the sql within this query, and
then run it.

Application.CurrentDb.QueryDefs("MyQuery").SQL = "Select * From TableName
Where FieldName = " & Me.[Field Name In the form]
Docmd.OpenQuery "MyQuery"
=======================================
Or create a query with reference to the fields in the form

Select TableName.* From TableName Where FieldName =
Forms![FormName]![FieldName]

And create a button on the form to run the query
--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benefit from it.

Good luck

"Cindy" wrote:

> I have a query and I'm wondering is there a way to build a form that runs the
> query and you can change certain conditions on the query through the form?

Cindy

unread,
Nov 3, 2005, 2:12:03 PM11/3/05
to
Is there a way to be prompted for and change the criteria each time I press
the button on the form. I would like to be able to change the criteria
before running the query from the form.

Ofer

unread,
Nov 3, 2005, 2:20:04 PM11/3/05
to
Then use the parameter in the query, and then just run the query

Select * From TableName Where FieldName = [Please enter value here:]

That will prompt the use with a message to enter a value, and the query will
filter the result by this value
To run the query
Docmd.OpenQuery "QueryName"

Cindy

unread,
Nov 3, 2005, 3:47:14 PM11/3/05
to
Ok that worked great thanks. What if you have more than 1 field that you
would like to specify a criteria for.

In the other field of the query I have a criteria of "K*" but there can be 2
criterias either K or T as the first character. Is there a way to specify
this. Do I use a parameter as well.

Ofer

unread,
Nov 3, 2005, 6:34:01 PM11/3/05
to
Try this

Select * From TableName Where FieldName Like "K*" Or FieldName Like "T*"

Cindy

unread,
Nov 4, 2005, 1:41:01 PM11/4/05
to
What if I want to be able to choose either K or T. Is there a way for the
form to prompt me for that field as well?

Ofer

unread,
Nov 5, 2005, 12:39:06 PM11/5/05
to
Select * From TableName Where FieldName Like [Please select First letter] &
"*" Or FieldName Like [Please select second letter] & "*"

So, the user can select two letters or if he/she press without entering any
letter, it will display all the records

0 new messages