By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,460 Members | 2,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,460 IT Pros & Developers. It's quick & easy.

How do you parameters (from code) to an Access Query

P: n/a
I really like using the stored queries in Access- the ones you make in query
designer then save. I know how to name parameters in those queries, but what
is a good way to send parameters to the query via variables via code from a
module's function or sub routine?

Thanks
William Roberts
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
It is possible to assign values to the parameters at runtime, e.g.:
Dim qdf as QueryDef
Set qdf = dbEngine(0)(0).QueryDefis("MyQuery")
qdf.Parameter("MyParam") = SomeValue

However, I find it much easier and more flexible to create the SQL statement
as a string in your code. For example, if have a form where the user enters
the values to use for selecting records, and you want to just ignore any
boxes that are left blank, it's very easy to build up a WHERE clause that
only contains the fields you need. To do the same with parameters, you have
to declare a parameter for each one, and so you finish up with a crazy WHERE
clause that has lots of meaningless phrases.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"Willam Roberts" <Wi*********@hotmail.com> wrote in message
news:mu*******************@nwrddc03.gnilink.net...
I really like using the stored queries in Access- the ones you make in query designer then save. I know how to name parameters in those queries, but what is a good way to send parameters to the query via variables via code from a module's function or sub routine?

Thanks
William Roberts

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.