473,769 Members | 5,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Runtime error 3061 - Too few parameters. Expected 1

121 New Member
Hi,

I am trying to run the following query in a recordset and i get the following error message

Runtime error 3061 - Too few parameters. Expected 1

i am using the following code

Expand|Select|Wrap|Line Numbers
  1.  
  2.     Dim dbsCurrent As Database
  3.     Dim rstQAssignedHrsSum As DAO.Recordset
  4.  
  5.  
  6.     Set dbsCurrent = CurrentDb
  7.  
  8.     Set rstQAssignedHrsSum = _
  9.       dbsCurrent.OpenRecordset("Q_SFormTotalHrs1", dbOpenDynaset)
The query is using the following SQL if i take out the reference to the form in the query criteria it works fine so it must be something to do with this any help is greatly appreciated

Regards Phill

Expand|Select|Wrap|Line Numbers
  1. SELECT T_ActiveSession.SessionID, T_ActiveSession.ProjID, T_ActiveSession.StartTime, T_ActiveSession.EndTime, T_ActiveSession.SessTypeID, DateDiff("n",[starttime],[endtime]-[break]-[downtime]) AS Expr1, T_ActiveSession.SessComplete, T_ActiveSession.Downtime, T_ActiveSession.Break
  2. FROM T_ActiveSession
  3. GROUP BY T_ActiveSession.SessionID, T_ActiveSession.ProjID, T_ActiveSession.StartTime, T_ActiveSession.EndTime, T_ActiveSession.SessTypeID, T_ActiveSession.SessComplete, T_ActiveSession.Downtime, T_ActiveSession.Break
  4. HAVING (((T_ActiveSession.ProjID)=[Forms]![F_ClientDetails]![SF_Session].[Form]![ProjID]));
  5.  
  6.  
Jan 19 '09 #1
3 4386
DonRayner
489 Recognized Expert Contributor
Hey Phill;

Does your query run correctly on it's own? Your error is looking like your query is expecting a parameter to be passed to it.
Jan 19 '09 #2
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi Don. Phill86's problem is caused by the reference to the form control, which is fine when run from the Access Query Editor but is invalid when run from VBA code. This particular one is further complicated by the reference being to a subform control.

There are a number of ways to resolve this. The simplest solution is to use a bespoke function in place of the direct reference to the form control in the Having clause, as function calls will be treated correctly by the SQL interpreter whereas form control references are treated as invalid.

Place the following two functions in a global code module (one which is visible from the Modules tab of the database window, or create a new one if not)

Expand|Select|Wrap|Line Numbers
  1. Public Function FormFieldValue(byVal FormName As String, byVal FieldName As String)
  2.     FormFieldValue = Forms(FormName).Controls(FieldName)
  3. End Function
  4.  
  5. Public Function SubFormFieldValue(ByVal FormName As String, ByVal SubFormName As String, ByVal FieldName As String)
  6.     SubFormFieldValue = Forms(FormName).Controls(SubFormName).Form.Controls(FieldName)
  7. End Function
The first of these can be used when referring to a control value on a main form, the second for a subform. To use the second function in place of your direct form control reference in your query alter the SQL code for your existing query as shown below:

Expand|Select|Wrap|Line Numbers
  1. SELECT T_ActiveSession.SessionID, T_ActiveSession.ProjID, T_ActiveSession.StartTime, T_ActiveSession.EndTime, T_ActiveSession.SessTypeID, DateDiff("n",[starttime],[endtime]-[break]-[downtime]) AS Expr1, T_ActiveSession.SessComplete, T_ActiveSession.Downtime, T_ActiveSession.Break
  2. FROM T_ActiveSession
  3. GROUP BY T_ActiveSession.SessionID, T_ActiveSession.ProjID, T_ActiveSession.StartTime, T_ActiveSession.EndTime, T_ActiveSession.SessTypeID, T_ActiveSession.SessComplete, T_ActiveSession.Downtime, T_ActiveSession.Break
  4. HAVING (((T_ActiveSession.ProjID)=SubFormFieldValue("F_ClientDetails", "SF_Session", "ProjID")));
  5.  
Or, from the Access Query Editor with the query loaded you can simply replace the criteria referring to Forms![F_ClientDetails]... etc

with

Expand|Select|Wrap|Line Numbers
  1. SubFormFieldValue("F_ClientDetails", "SF_Session", "ProjID")
-Stewart
Jan 19 '09 #3
phill86
121 New Member
Hi Stuart/Don

Many thanks works a treat

Regards Phill
Jan 20 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4439
by: Reggie | last post by:
Hi and TIA! I have a query that uses 2 values from my form as criteria for 2 fields in the query. I can select the options and open the query. I can base a form on the query and launch it from my criteria form with no problem. However if I try to open a recordset object against the query from this same criteria form I receive the (error # 3061 Too few parameters. expected 2.). I've tried first opening the query from code, which worked...
3
4019
by: colm | last post by:
i get the above runtime error on the following line of code when i try to update a reord in my form when it gets to the line Set rs = DBEngine(0)(0).OpenRecordset(strSql) the entire code is posted below
2
5545
by: Steve Richfield | last post by:
There have been LOTS of postings about error 3061, but mine seems to be an even simpler case than the others. I have a simple **FUNCTIONING** query called qryEdits. Copying the SQL from the query, it reads: SELECT Edits.Pattern, Edits.From, Edits.To FROM Edits WHERE (((Edits.Language)=!.)); The idea is to select just the language-appropriate records from the
2
5939
by: fanfromfla | last post by:
I am using a database that has worked for many years for a holiday project for needy families. My organization recently upgraded its server and changed everyone to Windows XP. I just mention that in case that has anything to do with the problem. There are pre-set reports that can be run with this database. I am getting a Runtime Error 3061 with one of them. It says Too Few Parameters. Expected 1. I have tried to trouble-shoot, but am...
11
3353
by: MLH | last post by:
If this is what MySQL is set to... SELECT DISTINCTROW qryVehiclesNowners5.SerialNum, qryVehiclesNowners5.VDescr, qryVehiclesNowners5.Owner, qryVehiclesNowners5.VehicleJobID , tblVehicleJobs.Reclaimed, tblVehicleJobs.VSaleID, tblVehicleJobs.ENF262Written FROM qryVehiclesNowners5 INNER JOIN tblVehicleJobs ON qryVehiclesNowners5.VehicleJobID = tblVehicleJobs.VehicleJobID WHERE (tblVehicleJobs.Reclaimed=No AND tblVehicleJobs.VSaleID Is Null...
4
7164
by: Richard Hollenbeck | last post by:
I thought I was very specific in this SQL request. There is a form open with a selected record (and a corresponding "lngRecipeID" on that form. The table also has a field called "lngRecipeID". But I keep getting this error: Runtime Error 3061: Too Few Parameters expected 1. What should I be looking for to fix this? Here's my code so far: Private Sub cmdAddIngredientToRecipe_Click() Dim dbGetRecipeID As DAO.Database
1
22305
by: Richard Hollenbeck | last post by:
I wonder what I'm missing? I really feel like a retard because I've been screwing with some code for a very long time. I just must be missing something very simple. In the following example, I've stripped away everything that doesn't cause the error to make my question a little simpler. Here's the problem in its simplest form inside a report: Dim db As DAO.Database
3
3833
by: Kassimu | last post by:
Hi there, I have a table with thousands of record entries, usually the user searches this table through SearchForm resulting into some recordset. What I need to do on this recordset is to concatenate the contents of all the records for one field-, and populate the resulting into textbox of a form Private Sub Form_Load() Dim db As Database Dim rstUpdates As Recordset Set db = CurrentDb Set rstUpdates = db.OpenRecordset("Daily...
8
2992
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
9423
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
10045
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
9994
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
9863
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
8872
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...
0
5299
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.