473,563 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ 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 23167
-----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:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQSEm7IechKq OuFEgEQKxvgCePW 6YvSxC3nwo3NU0h 4ZnazAtB6YAoOjY
mKKehSRPtI1JbYI 0G80FOZZw
=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******* ************@ne wsread1.news.pa s.earthlink.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:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQSEm7IechKq OuFEgEQKxvgCePW 6YvSxC3nwo3NU0h 4ZnazAtB6YAoOjY
mKKehSRPtI1JbYI 0G80FOZZw
=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("q uery name")
qd.parameter(0) = "first parameter"
qd.parameter(1) = "2nd parameter"

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

=====

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:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQSKJ2IechKq OuFEgEQI7NACg/aCL9GHG2hJyRgjd dh2pBvQJRVwAoMu u
vgV4qO6le8OVeDY Y+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******* ************@ne wsread1.news.pa s.earthlink.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:::mg f00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQSEm7IechKq OuFEgEQKxvgCePW 6YvSxC3nwo3NU0h 4ZnazAtB6YAoOjY
mKKehSRPtI1Jb YI0G80FOZZw
=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
3244
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 QueryB, and when I open it directly, it displays what I want. When I open the report from a command button on a form using this code:
2
6533
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 tblClearance. I was thinking of placing the code on the form's BeforeUpdate event so that it will fire whether the user closes the form or attempts...
2
2080
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 using an input box so that I could control the default date in each case (based on the current day of week and other variables). Each function...
2
1625
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 twice for dtCutoff. I've verified I'm using the same spelling and capitalization. Is there a way to make it only prompt once?
4
8218
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 is built into the form and so is not a problem. Then the second and third criteria prompt me for parameters. This all works fine and I get the info...
13
4212
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 solution here - until now. This one is driving me crazy. I am making my first attempt at creating a runtime application. I am using Access 2003...
2
13993
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 into SQL view to change the date range. This is what I have so far: TRANSFORM Count(.ID) AS CountOfID SELECT ., Count(.ID) AS FROM
5
5292
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 user prompted for them). Based on a Microsoft page (http://support.microsoft.com/kb/287437), I tried the following approach: Private Sub...
2
1683
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 works well and when you open the form it prompts you to enter your parameters,. But my question is how do yo get that dialog box prompt to appear again...
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2082
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 we have to send another system

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.