473,466 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VBA Run Query and Prompt forQuery Parameters

I would like to run a query from VBA. The query will be one with
parameters. Is there a way to run the query and have Access prompt
for the values like it does if I where to execute it through the
database window?
Nov 13 '05 #1
3 23152
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If you run a parameter query thru VBA w/o supplying the parameters, the
query will "ask" for them in pop-up prompts.

You could also set up the query to use values in an open form: this
will allow the query to retrieve the values w/o a pop-up prompt. E.g.:

Query SQL view:

PARAMETERS Form!form_name!control_name TEXT;
SELECT ...
FROM ...
WHERE text_column = Form!form_name!control_name

See the Access Help article on PARAMETERS declaration.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQSEm7IechKqOuFEgEQKxvgCePW6YvSxC3nwo3NU0h4Znaz AtB6YAoOjY
mKKehSRPtI1JbYI0G80FOZZw
=Qutp
-----END PGP SIGNATURE-----
Ryan Hubbard wrote:
I would like to run a query from VBA. The query will be one with
parameters. Is there a way to run the query and have Access prompt
for the values like it does if I where to execute it through the
database window?


Nov 13 '05 #2
Thanks for the reply. When I run a query that specifies parameters
(without specifing them of course) I get a en error "Too few
parameters. Expected <n>" where n is the number of parameters. I'm
using Office 2000 and DAO 3.6. How do I make Access "ask" for the
parameters?

Also do you know if it is possible to get the recordset from an open
query? I would like to be able to gather data from a query that is
currently open. I can get the QueryDef opject from Queries that are
open but can't seem to get the recordset. Is it possible?

Thanks

MGFoster <me@privacy.com> wrote in message news:<0G*******************@newsread1.news.pas.ear thlink.net>...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If you run a parameter query thru VBA w/o supplying the parameters, the
query will "ask" for them in pop-up prompts.

You could also set up the query to use values in an open form: this
will allow the query to retrieve the values w/o a pop-up prompt. E.g.:

Query SQL view:

PARAMETERS Form!form_name!control_name TEXT;
SELECT ...
FROM ...
WHERE text_column = Form!form_name!control_name

See the Access Help article on PARAMETERS declaration.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQSEm7IechKqOuFEgEQKxvgCePW6YvSxC3nwo3NU0h4Znaz AtB6YAoOjY
mKKehSRPtI1JbYI0G80FOZZw
=Qutp
-----END PGP SIGNATURE-----
Ryan Hubbard wrote:
I would like to run a query from VBA. The query will be one with
parameters. Is there a way to run the query and have Access prompt
for the values like it does if I where to execute it through the
database window?

Nov 13 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I was wrong about running a parameters query from VBA & the qry "asking"
for the parameters. You do have to explicitly assign them. Like this:

set qd = db.querydefs("query name")
qd.parameter(0) = "first parameter"
qd.parameter(1) = "2nd parameter"

' get data into a recordset
set rs = qd.openrecordset()

=====

I believe I once saw a discussion about accessing a query's datasheet
view, but, I can't remember much about it 'cuz I don't ever do that.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQSKJ2IechKqOuFEgEQI7NACg/aCL9GHG2hJyRgjddh2pBvQJRVwAoMuu
vgV4qO6le8OVeDYY+DTgCva6
=BW5n
-----END PGP SIGNATURE-----
Ryan Hubbard wrote:
Thanks for the reply. When I run a query that specifies parameters
(without specifing them of course) I get a en error "Too few
parameters. Expected <n>" where n is the number of parameters. I'm
using Office 2000 and DAO 3.6. How do I make Access "ask" for the
parameters?

Also do you know if it is possible to get the recordset from an open
query? I would like to be able to gather data from a query that is
currently open. I can get the QueryDef opject from Queries that are
open but can't seem to get the recordset. Is it possible?

Thanks

MGFoster <me@privacy.com> wrote in message news:<0G*******************@newsread1.news.pas.ear thlink.net>...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If you run a parameter query thru VBA w/o supplying the parameters, the
query will "ask" for them in pop-up prompts.

You could also set up the query to use values in an open form: this
will allow the query to retrieve the values w/o a pop-up prompt. E.g.:

Query SQL view:

PARAMETERS Form!form_name!control_name TEXT;
SELECT ...
FROM ...
WHERE text_column = Form!form_name!control_name

See the Access Help article on PARAMETERS declaration.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQSEm7IechKqOuFEgEQKxvgCePW6YvSxC3nwo3NU0h4Znaz AtB6YAoOjY
mKKehSRPtI1JbYI0G80FOZZw
=Qutp
-----END PGP SIGNATURE-----
Ryan Hubbard wrote:

I would like to run a query from VBA. The query will be one with
parameters. Is there a way to run the query and have Access prompt
for the values like it does if I where to execute it through the
database window?


Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Steven Stewart | last post by:
Hi there, I have a query (QueryB) that is based on the results of another query (QueryA). When I open QueryB itself, it displays the exact records that I want. I have a report based on...
2
by: Paul Wagstaff | last post by:
Hi there I have 2 tables: tblAccuracy & tblClearance Users add new records to tblAccuracy using frmRegister. Under specific conditions I need to append the current record from frmRegister into...
2
by: jmev7 | last post by:
I had a query with a criteria in a date field reading "> And <", and when run, it correctly prompted first for the param, and then for the param. I then created functions to replace these params...
2
by: HateSpam | last post by:
I have a paramter query that wants either of 2 date fields in a table to be before a certain date. Select * from tblExample where Date1 < or Date2 < When I open this query, it prompts me...
4
by: Lightning Tony | last post by:
This is probably a really silly question but I am exhausted and cant seem to find the answer. I have a query that I run from a command button on a form. The query has three criteria set. The first...
13
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a...
2
by: sixdeuce62 | last post by:
Hello, I am trying to create a query that will prompt me to enter the parameter value if beginning date and ending date. I have created everything I need in the query, but I have to manually go...
5
by: dana1 | last post by:
Hello Experts! Does anyone know if there is a way to set the values of query parameters from VBA for a report's recordsource? (i.e., I want to set the values of the parameters and NOT have the...
2
by: dympna | last post by:
I have created a dialog box in a query that will prompt the person to input the parameters they want to stipulate the query to search on... I have created a form based on this query, everthing...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.