473,698 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using form control values in queries

I'm trying to use a query whose SQL view is shown below to get a
recordset of all first quarter records from a table for a year that is
in the textbox of a form, so I can sum up the totals for the first
quarter for every person and display them on the form. The query works
fine when I preview it in the query builder, but when I try to open a
recordset in vb code with the query I get "too few parameters expected
one". It seems for some reason it can't resolve the value of the txtform
control when I run it in the vb code, whereas it does just fine running
it from query builder. Is there some way around this problem?
SELECT DISTINCT Quality.[UW Last Name], Quality.[Review Year],
Quality.[Review Month], Quality.Q1, Quality.Q2, Quality.Q3, Quality.Q4,
Quality.Q5 FROM Quality
WHERE (((Quality.[Review Year])=[Forms]![frmNewQuarter]![txtYear]) AND
((Quality.[Review Month])="01")) OR (((Quality.[Review
Year])=[Forms]![frmNewQuarter]![txtYear]) AND ((Quality.[Review
Month])="02")) OR (((Quality.[Review
Year])=[Forms]![frmNewQuarter]![txtYear]) AND ((Quality.[Review
Month])="03"))
ORDER BY Quality.[UW Last Name];

PS I have a similar query that I am assigning to the forms recordsource
and it works just fine within the vb code.
Although the weird thing is it doesn't display on the form until I go to
records > remove filter/sort

Here it is:

"SELECT SCQ403Forth.Emp loyeeID, SCQ403Forth.Fir stName,
SCQ403Forth.Las tName, SCQ403Forth.Pro ductivity, SCQ403Forth.[P Rank],
SCQ403Forth.[WP Rank], SCQ403Forth.Tur ntime, SCQ403Forth.[TT Rank],
SCQ403Forth.[WTT Rank],
FROM SCQ403Forth WHERE (((SCQ403Forth. Quarter) =
[Forms]![frmSCDisplay]![cmbQuarter]) And ((SCQ403Forth.Y ear) =
[Forms]![frmSCDisplay]![cmbYear])) ORDER BY SCQ403Forth.Las tName; "

I know I could probably get around it using the arduous process of
making a querydef with a parameter but I can't find the reference book i
used to have on doing this and the help on this topic inside access is
useless in this situation. Is there an easier way? If not how would I do
it with parameters?

Thanks in Advance,
Joe Del Medico

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #1
1 3555
DAO does not use the Expression Service to resolve the form references.

In code, you need to construct the query string dynamically by concatenating
the values into the string:
Dim strSQL As String
strSQL = "SELECT ... WHERE (Quality.[ReviewYear] = " &
Forms![frmNewQuarter]![txtYear] & ") AND ...

Alternatively, declare the parameters, and supply them before opening the
recordset:
Dim qdf As QueryDef
Set qdf = dbEngine(0)(0). QueryDefs("Name OrYourQueryHere ")
qdf.Parameters( 0) = Forms![frmNewQuarter]![txtYear]
qdf.Parameters (1) = ...

To declare the parameters in the query itself:
1. Open the query in design view.
2. Choose Parameters from the Query menu.
3. Type in the names and data types of your parameters, e.g.:
Forms![frmNewQuarter]![txtYear] Long

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Joseph Del Medico" <jo*********@ya hoo.com> wrote in message
news:40******** **************@ news.newsgroups .ws...
I'm trying to use a query whose SQL view is shown below to get a
recordset of all first quarter records from a table for a year that is
in the textbox of a form, so I can sum up the totals for the first
quarter for every person and display them on the form. The query works
fine when I preview it in the query builder, but when I try to open a
recordset in vb code with the query I get "too few parameters expected
one". It seems for some reason it can't resolve the value of the txtform
control when I run it in the vb code, whereas it does just fine running
it from query builder. Is there some way around this problem?
SELECT DISTINCT Quality.[UW Last Name], Quality.[Review Year],
Quality.[Review Month], Quality.Q1, Quality.Q2, Quality.Q3, Quality.Q4,
Quality.Q5 FROM Quality
WHERE (((Quality.[Review Year])=[Forms]![frmNewQuarter]![txtYear]) AND
((Quality.[Review Month])="01")) OR (((Quality.[Review
Year])=[Forms]![frmNewQuarter]![txtYear]) AND ((Quality.[Review
Month])="02")) OR (((Quality.[Review
Year])=[Forms]![frmNewQuarter]![txtYear]) AND ((Quality.[Review
Month])="03"))
ORDER BY Quality.[UW Last Name];

PS I have a similar query that I am assigning to the forms recordsource
and it works just fine within the vb code.
Although the weird thing is it doesn't display on the form until I go to
records > remove filter/sort

Here it is:

"SELECT SCQ403Forth.Emp loyeeID, SCQ403Forth.Fir stName,
SCQ403Forth.Las tName, SCQ403Forth.Pro ductivity, SCQ403Forth.[P Rank],
SCQ403Forth.[WP Rank], SCQ403Forth.Tur ntime, SCQ403Forth.[TT Rank],
SCQ403Forth.[WTT Rank],
FROM SCQ403Forth WHERE (((SCQ403Forth. Quarter) =
[Forms]![frmSCDisplay]![cmbQuarter]) And ((SCQ403Forth.Y ear) =
[Forms]![frmSCDisplay]![cmbYear])) ORDER BY SCQ403Forth.Las tName; "

I know I could probably get around it using the arduous process of
making a querydef with a parameter but I can't find the reference book i
used to have on doing this and the help on this topic inside access is
useless in this situation. Is there an easier way? If not how would I do
it with parameters?

Thanks in Advance,
Joe Del Medico

Nov 13 '05 #2

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

Similar topics

2
17352
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 (update, append) should be activated in order to transfer data to other tables. I tried to avoid any coding in VB, as I am not a professional, but I have found a statement in an article, that, unlike select queries, form's Input Property can't be...
5
10114
by: Deborah V. Gardner | last post by:
I would like to use "Yes" and "No" checkboxes on a subform. The problem is that when I click the Yes checkbox on the subform, all of the checkboxes are checked. Currently, I have a field "Refused." It is defined as a text field. A "Y" means that the service has been refused; an "N" indicates it has been accepted. If the field is Null, the question has not been answered, i.e. we don't know if it has been refused or not. I want the user...
1
1535
by: Simon Matthews | last post by:
Hope someone can help an Access beginner! I've just started keeping my surgical logbook on access and it's a simple flat-file affair. I have created several queries that will list cases performed at different hospitals and reports based on the queries to print out the relavent details. What I would like to do is have a summary sheet in the Report Footer section that lists a grid of each type of procedure performed as well as the...
1
3420
by: Aaron | last post by:
Hello fellow programmers, I am trying to run an append/update query from code, a command button on a form initiates the queries. the format i am using is; _____________________________________________________ SELECT "criteria"
2
1683
by: Tim Pollard | last post by:
Hi I'm hoping someone can help me with an access problem I just can't get my head around. I normally use access as a back end for asp pages, just to hold data in tables, so queries within access are a mystery to me, but I can't think of any other way of dealing with the problem. I have six tables in my db: tblCompanies (list of companies, primary key CompanyID) tblOffices (list of office buildings including what company owns/uses
3
2752
by: google | last post by:
I'm developing an application for use within my company in Access 2003. I'm new to '03, the application I did for my former employer was in '97. The two applications have similar functionality (we're sales offices, and I'm doing things such as associate directories, commission calculations, order tracking, etc.). 2003 seems to have a few extra features, but I seem to continually run in to oddities that seem like they SHOULD work, but...
12
2360
by: Tom | last post by:
Hello, I have a database of employee data in access and I am trying to create a form with combo boxes for criteria (ex. gender, office, position, etc.) that let the user select criteria from drop down menus (ex. they may select Male, New York, Manager) and those criteria will be used to run a query (ie Query by Form). I can do this with text boxes but when I tried to use combo boxes no records were returned in the query. Any idea what...
0
7665
MMcCarthy
by: MMcCarthy | last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access. Angle brackets <> are used in place of some syntax elements you must supply. The description of these elements will be in the contained in the angle brackets. Square brackets are used to show which parts are optional. Basic SELECT query SELECT <field list> FROM <table/query name(s)>
1
2146
by: bowl3969 | last post by:
I have a form with a lot of controls on it that will be used to update tables. The nature of the data is such that I will be running queries based on the control name. sqlstr="insert into tblgames (score) values (me.pbScore1);" doCmd.runsql(sqlstr) "insert into tblgames (score) values (me.pbScore2);" doCmd.runsql(sqlstr) insert into tblgames (score) values (me.pbScore3) etc.. This may be a lack of experience thing but I would like to...
0
8609
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
9031
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
8871
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...
0
7739
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
6528
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
4371
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.