473,789 Members | 3,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

query question

I have a query that uses a value from a form as a criteria. For
example looking for all customers belonging to a particular party.
the criteria on the QBE looks like [Forms]![frmParty]![PartyID]

I am trying to open the query in VBA using DAO. If I simply use
OpenRecordset (with the form open that contains the criteria value) it
fails. If I hard code a value in the query instead e.g. customerID 33
its fine. Alternatively if I change the criterion to a parameter then
use a querydef passing a value in for the parameter its fine.

This is the SQL of the query I'm trying to open.

SELECT DISTINCT qryHirePrice.Hi rePriceID, qryHirePrice.Hi rePrice,
Sum(qryPayments .PaymentAmount) AS SumOfPaymentAmo unt, [HirePrice]-
[SumOfPaymentAmo unt] AS Balance, qryHirePrice.Pa rtyID
FROM qryHirePrice INNER JOIN qryPayments ON qryHirePrice.Hi rePriceID =
qryPayments.Hir ePriceID
GROUP BY qryHirePrice.Hi rePriceID, qryHirePrice.Hi rePrice,
qryHirePrice.Pa rtyID
HAVING (((qryHirePrice .PartyID)=[Forms]![frmParty]![PartyID]));

this is the VBA code

Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
set rst = db.OpenRecordse t("qryHirePrice Payment")

thanks
Allan

Mar 19 '07 #1
4 2983
yes, that's correct; you have to hard-code the value or pass the value to a
querydef. a third alternative is to use a string variable to hold the SQL
statement and pass to the recordset, concatenating the value from the form
control into the string, as

Dim strSQL As String
strSQL = "SELECT DISTINCT qryHirePrice.Hi rePriceID..." _
& "...HAVING qryHirePrice.Pa rtID = " _
& [Forms]![frmParty]![PartyID]

Set rst = db.OpenRecordse t(strSQL)

hth
"allanx38" <al******@yahoo .co.ukwrote in message
news:11******** **************@ e65g2000hsc.goo glegroups.com.. .
I have a query that uses a value from a form as a criteria. For
example looking for all customers belonging to a particular party.
the criteria on the QBE looks like [Forms]![frmParty]![PartyID]

I am trying to open the query in VBA using DAO. If I simply use
OpenRecordset (with the form open that contains the criteria value) it
fails. If I hard code a value in the query instead e.g. customerID 33
its fine. Alternatively if I change the criterion to a parameter then
use a querydef passing a value in for the parameter its fine.

This is the SQL of the query I'm trying to open.

SELECT DISTINCT qryHirePrice.Hi rePriceID, qryHirePrice.Hi rePrice,
Sum(qryPayments .PaymentAmount) AS SumOfPaymentAmo unt, [HirePrice]-
[SumOfPaymentAmo unt] AS Balance, qryHirePrice.Pa rtyID
FROM qryHirePrice INNER JOIN qryPayments ON qryHirePrice.Hi rePriceID =
qryPayments.Hir ePriceID
GROUP BY qryHirePrice.Hi rePriceID, qryHirePrice.Hi rePrice,
qryHirePrice.Pa rtyID
HAVING (((qryHirePrice .PartyID)=[Forms]![frmParty]![PartyID]));

this is the VBA code

Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
set rst = db.OpenRecordse t("qryHirePrice Payment")

thanks
Allan

Mar 19 '07 #2

How does it fail? What error are you getting if any?

Mar 19 '07 #3
On Mar 19, 1:13 am, "storrboy" <storr...@sympa tico.cawrote:
How does it fail? What error are you getting if any?
Thanks guys. I had fallen back on the SQL string idea but it strikes
me as a bit long winded, call me lazy ...

The original error I get is 3061, Too few parameters. Expected 1.
Maybe I can pass the parameter in using a position as opposed to via a
name as I usually do.

Allan

Mar 19 '07 #4
Does the query run as just as query???
bobh.
On Mar 18, 8:48 pm, "allanx38" <allan...@yahoo .co.ukwrote:
I have a query that uses a value from a form as a criteria. For
example looking for all customers belonging to a particular party.
the criteria on the QBE looks like [Forms]![frmParty]![PartyID]

I am trying to open the query in VBA using DAO. If I simply use
OpenRecordset (with the form open that contains the criteria value) it
fails. If I hard code a value in the query instead e.g. customerID 33
its fine. Alternatively if I change the criterion to a parameter then
use a querydef passing a value in for the parameter its fine.

This is the SQL of the query I'm trying to open.

SELECT DISTINCT qryHirePrice.Hi rePriceID, qryHirePrice.Hi rePrice,
Sum(qryPayments .PaymentAmount) AS SumOfPaymentAmo unt, [HirePrice]-
[SumOfPaymentAmo unt] AS Balance, qryHirePrice.Pa rtyID
FROM qryHirePrice INNER JOIN qryPayments ON qryHirePrice.Hi rePriceID =
qryPayments.Hir ePriceID
GROUP BY qryHirePrice.Hi rePriceID, qryHirePrice.Hi rePrice,
qryHirePrice.Pa rtyID
HAVING (((qryHirePrice .PartyID)=[Forms]![frmParty]![PartyID]));

this is the VBA code

Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
set rst = db.OpenRecordse t("qryHirePrice Payment")

thanks
Allan

Mar 19 '07 #5

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

Similar topics

9
3407
by: majsen | last post by:
Hi, I have problem running this query. It will time out for me... My database are small just about 200 members. I have a site for swaping appartments (rental). my query should look for match in a triangle. Like this member A -> B->C A give his appartment to B. B gives his appartment to C and finally C gives his appartment to A Soo my query looks for matching parameters like rooms, location, size
8
3272
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run simultaneously 4 similar queries it takes nearly 5 minutes instead of 4 times 9 seconds or something near of that. here is a sample query: select mertido, fomeazon, ertektipus, mertertek from t_me30 where fomeazon in (select distinct fomeazon...
3
14129
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record (and store it in field 2). > > I would like to run a query that returns all the data in the table plus the > record number, in a similar sense to the getuser() command to get the User's > Identity, I would like a GetRecord() command.
3
3092
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table before rowID answID qryrow questionID datafield 1591 12 06e 06e 06e question 1593 12 06f 06f 06f question 1594 12 answer to the question 06f
7
3391
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always either AND or OR but never mixed together. We can use Northwind database for my question, it is very similar to the structure of the problem on the database I am working on. IF(SELECT OBJECT_ID('REPORT')) IS NOT NULL DROP TABLE REPORT_SELECTION
6
4849
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID SalesManName AT Alan Time
2
2040
by: mmitchell_houston | last post by:
I'm working on a .NET project and I need a single query to return a result set from three related tables in Access 2003, and I'm having trouble getting the results I want. The details: Question ------------ QuestionID QuestionText Question_MediaTypeID
22
31212
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for June, and will return all records in that month.
3
2064
by: Richard Hollenbeck | last post by:
I am very sorry about the (almost) re-post, but you will see that my first question wasn't very clear; I have another question I posted this morning called, "in DAO: Run time error 3061 Too few parameters...." I have read many articles on the web about how to make a dynamic report based on a cross-tab query. But for some reason mine never works right. First, my saved query's criteria is the data in an open form's combo box. So the...
16
3521
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate (tried a groups query, but "count" won't work), then do an update query to change the duplicate to...
0
9665
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
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
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...
0
9983
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7529
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
6768
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.