473,794 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A2K3: Running query via currentdb.openr ecordset()

I have a parameter query named "qry_employee_i nfo_reports" that I need
to run in the OnOpen event of a form. I'm after its total number of
records. The query's got several joins in it, and one of them is to
query "qry_last_trans ition," which is also a parameter query. Both
querys use the same parameter: a control called "txtSecondD ate" on a
pop up form.

What I've been trying to do up to this point is to open up this
parameter form, set the date of "txtSecondD ate" to the appropriate
date, and then use the CurrentDB.OpenR ecordset method like this: Set
GetEmployeeCoun t =
CurrentDB.OpenR ecordset("qry_e mployee_info_re ports"). I've tried using
different types like dbOpenForwardOn ly, etc. as well. No matter what I
try though, i keep getting the "Too few parameters. Expected 1."
error; I suspect because of "qry_last_trans ition."

My questions are then first, how can I run this query in code to get
its total number of records; and second, how is what I'm doing here any
different then when I run a report based on this query? When I run a
report, whatever needs the parameter just looks at the parameter form
and gets it, right? Why wouldn't this be the same thing?

Any help is greatly appreciated.

-Josh Nikle

Mar 16 '06 #1
1 10823
'---------

dim qdf as dao.querydef
dim db as dao.database
dim rs as dao.recordset

set db = currentdb
set qdf = db.querydefs("q ry_employee_inf o_reports")

qdf.parameters( 1) = eval(qdf.parame ters(1))

set rs = qdf.openrecords et.

'---------
CurrentDB.OpenR ecordset is a DAO method.

DoCmd.OpenRepor t is an Access method.

When you use Access methods, the query is passed through
Access, which gives Access the chance to evaluate Form
references. When you use DAO methods, Access never gets
to see the sql, and never gets to evaluate the Form references

An alternative is to use a table instead of a form. Join
the query to the parameter table, and write the parameter
values to the table before calling the query.
(david)
<jn****@gmail.c om> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
I have a parameter query named "qry_employee_i nfo_reports" that I need
to run in the OnOpen event of a form. I'm after its total number of
records. The query's got several joins in it, and one of them is to
query "qry_last_trans ition," which is also a parameter query. Both
querys use the same parameter: a control called "txtSecondD ate" on a
pop up form.

What I've been trying to do up to this point is to open up this
parameter form, set the date of "txtSecondD ate" to the appropriate
date, and then use the CurrentDB.OpenR ecordset method like this: Set
GetEmployeeCoun t =
CurrentDB.OpenR ecordset("qry_e mployee_info_re ports"). I've tried using
different types like dbOpenForwardOn ly, etc. as well. No matter what I
try though, i keep getting the "Too few parameters. Expected 1."
error; I suspect because of "qry_last_trans ition."

My questions are then first, how can I run this query in code to get
its total number of records; and second, how is what I'm doing here any
different then when I run a report based on this query? When I run a
report, whatever needs the parameter just looks at the parameter form
and gets it, right? Why wouldn't this be the same thing?

Any help is greatly appreciated.

-Josh Nikle

Mar 16 '06 #2

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

Similar topics

1
8212
by: el Benno | last post by:
If CurrentDb.OpenRecordset("table").EOF Then ... works fine If CurrentDb.OpenRecordset("Query").EOF Then ... doesn't????????? microsft help is outstanding too - surprise surprise any help greatly appreciated! / Ben
6
17161
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how this can be done? I've tried setting the default value of the text fields on the form to be equal to ! using Access' expression
6
2246
by: sghi | last post by:
Hi All, I'm new to this group and quite new to access/vba. So, shortly after beginning to write a simple application for my wife, I came across a blocking problem: I need to intercept the sql statement that stay behind a current, but not yet saved query. When I work on saved queries I use: strCurrentName = CurrentObjectName Dim dbsCurrent As Database Set dbsCurrent = CurrentDb
13
4521
by: Arno R | last post by:
Hi all, I am deploying an A2k app to users with different versions of Access. Using Access 2000 the relinking on startup (on deploying a new frontend or when backend has changed) is very fast. It takes about 4-5 seconds to relink some 50 tables. (I am relinking, not refreshing) Using Access 2003 the relinking is very slow compared with Access 2000. Now It takes about 1,5 to 2 minutes !! to relink the same 50 tables. I am testing...
3
2163
by: Phil Stanton | last post by:
I have a number of queries which use code for the output of 1 or more fields. For example Address:GetAddress(AddressID, True, 60) Address ID Points to an Address in a table - Address Line1, Line 2, Line 3, Town, County, Post Code, Country. The True is whether to include the country and the 60 is the maximum line length (after which a line feed is inserted). All this is to output to a formatted RTF file for a handbook. In addition, I...
9
2780
by: QCLee | last post by:
Sir can you help me to transfer my Access Query to MS excel? i have a command button on the form to export the parameter query named "HVACWindwardQuery" to excel spreadsheet and i got the codes from searching on the internet and books but the problem is when i run the command button "Export" it just only open the Blank Spreadsheet, no data at all that it came from my query named "HVACWindwardQuery" and there's an error on it...
4
8982
kcdoell
by: kcdoell | last post by:
Hello: What is the best way to stop a report from running if the query is empty? Currently, I have a form that has a command button on it. The user has to make selections from 3 combo boxes on the form and then via the cmdbutton the report opens in preview mode. I want to stop it from executing if the query is empty. I thought I could do this by checking the record count by the following code but I error out with the following message: ...
3
5573
habby0123
by: habby0123 | last post by:
I am trying to export data to Excel from a query in Access. There is a unique "Sales Region ID" and various "Territory#'s" for each Region. I would like one excel workbook for each region, and a worksheet for each Territory # assigned to that region. I do something similiar with a report that I programmatically convert to a pdf and it works fine, but I'm having a little trouble with the excel export. Can someone give me some advice? (Below is my...
8
2996
Cintury
by: Cintury | last post by:
The problem is I have a function that I've created and stored in a module. I call it as an expression (e.g. total: Function(parameter)). I'm receiving the error 3061: too few parameters, expected 1. Now the query and database are already open so I'm not entirely sure of any connection strings I may need. I think part of the problem may be that the parameter I am using to call the function is part of the query. I am not sure how to come by this...
0
9671
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10161
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9035
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
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
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.