473,396 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Passing parameters to queries using VBA

Guys I need your help/Advice...

In my Access Database I have a query (lets say qry1) and in this query
i have 2 fields for start and end date, which is provided by 2 Get
functions.

also i have qry2 based on qry1
then qry3 based on qry2
and finally qry4(using sql in code) based on qry3, and non of these 3
queries have the start and end date fields.

now here is the problem: I am trying to set the criteria in qry4 and
then open a record set on this query(qry4) to use the data that it
pulls out...

Expand|Select|Wrap|Line Numbers
  1. strsql = ""
  2. strsql = "SELECT Sum AS AREA_TOTAL " _
  3. & "FROM qry3 " _
  4. & "WHERE ENERGY_AREA like '" & Area & "';"
  5.  
  6. Set MyDB = CurrentDb
  7.  
  8. Set rst = MyDB.OpenRecordset(strsql)
  9.  
  10.  
but when the last line is executed I get this error message:

Runtime Error '3061':
Too few parameters, expected 2.

i also tried doing this:
Expand|Select|Wrap|Line Numbers
  1. strsql = ""
  2. strsql = "SELECT Sum AS AREA_TOTAL " _
  3. & "FROM qry3 " _
  4. & "WHERE ENERGY_AREA like '" & Area & "';"
  5.  
  6. Set MyDB = CurrentDb
  7.  
  8.  
  9. MyDB.QueryDefs("qry4").sql = strsql
  10.  
  11. Set rst = MyDB.OpenRecordset("qry4")
  12.  
  13.  
but when the last line is executed it gives me an error message saying
that the query does not exist or the name is not spelled correctly.
(Ps. I have created the query and the criteria does update once the
Select statement is run in the code!)

again the reason for this is that the query has not been populated as
the main query (qry1) needs 'strat date' and 'end date'!

Is there anyway I can pass these 2 parameters to qry4 directly using
code? If there is a way then this will definitly work as i tried
opening the query manually in the Query window and after I input the 2
dates in the input box the query ran successfully!

I would appreciate any help/suggestion guys,

Feb 1 '06 #1
1 2333
You could use two functions like:

Public Function StartFn() As Date
StartFn= GlStart
End Function

Public Function EndFn() As Date
EndFn = GlEnd
End Function

Where GlStart and GlEnd are two global date variables.

Your query which needs to filter on dates would then have a criterion:
Between StartFn() And EndFn()

Thick Quinker - I just never learn.

*** Sent via Developersdex http://www.developersdex.com ***
Feb 1 '06 #2

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

Similar topics

13
by: | last post by:
From ASP I run a query using MIN(some_field/parameter) Now I need to pass this parameter to the query from ASP code How do I do that? Syntax like MIN( / ) does not work
2
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
14
by: | last post by:
Hi, I was performing SQL UPDATE queries and I notice that they SUCCEED on the ExecuteNonQuery() call with NO exceptions raised BUT they fail at the Database. They say they succeed in the code...
6
by: dharmadam | last post by:
Is it possible to pass a column name or the order of the column name in the DB2 table table function. For example, I want to update the address of a person by passing one of the address column name...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
3
by: jgscott3 | last post by:
I have a number of queries that require various parameters. However, the parameters will change infrequently, so I do not want the user to have to respond to them every time they run the queries. ...
3
by: RoadRunner | last post by:
Hi, I am having a problem. I have a very simple employee database. The client needs to see everything on a form before any updates or deletions can be made. I have a form that loads with two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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,...
0
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...
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,...

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.