A way in code to input criteria into a certain column in a query

  • Thread starter Thread starter John
  • Start date Start date
J

John

I am having problems referencing a form to apply the
criteria to a query. Is there a way to edit the query to
actually write the criteria instead of referencing it.

Thanks
JOhn
 
Actually...you "kind of" can.

In most cases, you want to use the criteria for a form, or a report (you
don't say which).

So, if we have a report, and want to display all customers from my City of
Edmonton..we can make a form, with a UN-BOUND text box called txtCity. You
can enter the name of the city. You then for the button code to launch the
report


dim strWhere as string

strWhere = "City = " & "'" & txtCity & "'"

docmd.OpenReport "myReport",acViewPreview,,strWhere

Notice how we don't actually put any forms refs in the sql. That means you
simply build the report and use clean sql without any forms refs.

You can also use the above code/trick for forms. Take a look at the
following report screen shots to see how nice the above idea can become:

http://www.attcanada.net/~kallal.msn/ridesrpt/ridesrpt.html

If you are not trying to launch a report, or form...then just ask..and I can
post a few more code examples of how to make query with parameters ..but NOT
place the actual forms! ref in the sql.

I will say that using a form ref direct in the sql is easy..but then not
flexible. My above approach unfortunately does requite you to start wring
some code.
 
Back
Top