473,385 Members | 1,562 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,385 software developers and data experts.

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.EmployeeID, SCQ403Forth.FirstName,
SCQ403Forth.LastName, SCQ403Forth.Productivity, SCQ403Forth.[P Rank],
SCQ403Forth.[WP Rank], SCQ403Forth.Turntime, SCQ403Forth.[TT Rank],
SCQ403Forth.[WTT Rank],
FROM SCQ403Forth WHERE (((SCQ403Forth.Quarter) =
[Forms]![frmSCDisplay]![cmbQuarter]) And ((SCQ403Forth.Year) =
[Forms]![frmSCDisplay]![cmbYear])) ORDER BY SCQ403Forth.LastName; "

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 3499
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("NameOrYourQueryHere")
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*********@yahoo.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.EmployeeID, SCQ403Forth.FirstName,
SCQ403Forth.LastName, SCQ403Forth.Productivity, SCQ403Forth.[P Rank],
SCQ403Forth.[WP Rank], SCQ403Forth.Turntime, SCQ403Forth.[TT Rank],
SCQ403Forth.[WTT Rank],
FROM SCQ403Forth WHERE (((SCQ403Forth.Quarter) =
[Forms]![frmSCDisplay]![cmbQuarter]) And ((SCQ403Forth.Year) =
[Forms]![frmSCDisplay]![cmbYear])) ORDER BY SCQ403Forth.LastName; "

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
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...
5
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...
1
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...
1
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; ...
2
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...
3
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...
12
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...
0
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.