473,480 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Run-time error '3061' Too few parameters. Expected 1. Can't figure this out.

4 New Member
I'm trying to figure out why I'm getting this error. I'm relatively inexperienced. The nature of the following code is that a slightly different query is run whether or not the "ImportantDatesOnly" flag is true or not. The problem is that the query that runs while the flag is true fails, and the query for when the flag is false does not fail. The error occurs at db.OpenRecordset (last line in the code segment). The failing query does run fine when cut and paste directly into a new query and then run. I've underlined the sections that are different below. This is in Access 2007.


Code Segment
Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2. Dim rs As DAO.Recordset
  3. Dim strSQL As String
  4.  
  5. Set db = OpenDatabase(systemDbPath & "Data.accdb")
  6.  
  7. If ImportantDatesOnly = True Then
  8.     strSQL = "SELECT [etl].[TaskID], [qec].[EventID], [qec].[InstanceID], " & _
  9.              "IIf([tblEventException].[EventID] Is Null,IIf(([qec].[PeriodTypeID] Is Null) Or " & _
  10.              "([qec].[PeriodFreq] Is Null) Or ([qec].[InstanceID] Is Null), " & _
  11.              "[qec].[EventStart],DateAdd([qec].[PeriodTypeID], " & _
  12.              "[qec].[InstanceID]*[qec].[PeriodFreq],[qec].[EventStart])), " & _
  13.              "IIf([tblEventException].[IsCanned],Null,[tblEventException].[InstanceDate])) AS EventDate, " & _
  14.              "[qec].[EventDescrip], [qec].[Comment], [tblEventException].[IsCanned], " & _
  15.              "[tblEventException].[InstanceComment], [qec].[EventStart], [qec].[RecurCount], " & _
  16.              "[qec].[PeriodFreq], [ltPeriodType].[PeriodType] FROM ((qryEventCartesian As qec LEFT JOIN " & _
  17.              "tblEventException ON ([qec].[InstanceID] = [tblEventException].[InstanceID]) AND " & _
  18.              "([qec].[EventID] = [tblEventException].[EventID])) LEFT JOIN ltPeriodType ON " & _
  19.              "[qec].[PeriodTypeID] = [ltPeriodType].[PeriodTypeId]) RIGHT JOIN EventsTasksLink AS etl ON " & _
  20.              "[qec].[EventID] = [etl].[EventID] WHERE ((([etl].[TaskID]) = " & TaskID & ") And " & _
  21.              "(([qec].[IsImportant]) = True)) ORDER BY [qec].[EventID], [qec].[InstanceID];"
  22. Else
  23.     strSQL = "SELECT [etl].[TaskID], [qec].[EventID], [qec].[InstanceID], " & _
  24.              "IIf([tblEventException].[EventID] Is Null,IIf(([qec].[PeriodTypeID] Is Null) " & _
  25.              "Or ([qec].[PeriodFreq] Is Null) Or ([qec].[InstanceID] Is Null)," & _
  26.              "[qec].[EventStart],DateAdd([qec].[PeriodTypeID]," & _
  27.              "[qec].[InstanceID]*[qec].[PeriodFreq],[qec].[EventStart]))," & _
  28.              "IIf([tblEventException].[IsCanned],Null,[tblEventException].[InstanceDate])) AS EventDate, " & _
  29.              "[qec].[EventDescrip], [qec].[Comment], [tblEventException].[IsCanned], " & _
  30.              "[tblEventException].[InstanceComment], [qec].[EventStart], [qec].[RecurCount], " & _
  31.              "[qec].[PeriodFreq], [ltPeriodType].[PeriodType] FROM ((qryEventCartesian AS qec LEFT JOIN " & _
  32.              "tblEventException ON ([qec].[InstanceID] = [tblEventException].[InstanceID]) AND " & _
  33.              "([qec].[EventID] = [tblEventException].[EventID])) LEFT JOIN ltPeriodType ON " & _
  34.              "[qec].[PeriodTypeID] = [ltPeriodType].[PeriodTypeId]) RIGHT JOIN EventsTasksLink AS etl ON " & _
  35.              "[qec].[EventID] = [etl].[EventID] WHERE [etl].[TaskID] = " & TaskID & _
  36.              " ORDER BY [qec].[EventID], [qec].[InstanceID];"
  37. End If
  38.  
  39. Set rs = db.OpenRecordset(strSQL)
  40.  
Calculated Query that Works
Expand|Select|Wrap|Line Numbers
  1. SELECT [etl].[TaskID],[qec].[EventID],[qec].[InstanceID], IIf([tblEventException].[EventID] Is Null,IIf(([qec].[PeriodTypeID] Is Null) Or ([qec].[PeriodFreq] Is Null) Or ([qec].[InstanceID] Is Null), [qec].[EventStart],DateAdd([qec].[PeriodTypeID],[qec].[InstanceID]*[qec].[PeriodFreq],[qec].[EventStart])), IIf([tblEventException].[IsCanned],Null,[tblEventException].[InstanceDate])) AS EventDate, [qec].[EventDescrip], [qec].[Comment], [tblEventException].[IsCanned],[tblEventException].[InstanceComment], [qec].[EventStart],[qec].[RecurCount],[qec].[PeriodFreq],[ltPeriodType].[PeriodType] FROM ((qryEventCartesian As qec LEFT JOIN tblEventException ON ([qec].[InstanceID] = [tblEventException].[InstanceID]) AND ([qec].[EventID] = [tblEventException].[EventID])) LEFT JOIN ltPeriodType ON [qec].[PeriodTypeID] = [ltPeriodType].[PeriodTypeId]) RIGHT JOIN EventsTasksLink AS etl ON [qec].[EventID] = [etl].[EventID] WHERE (([etl].[TaskID]) = 8) ORDER BY [qec].[EventID], [qec].[InstanceID];
  2.  
Calculated Query that Doesn't Work
Expand|Select|Wrap|Line Numbers
  1. SELECT [etl].[TaskID], [qec].[EventID], [qec].[InstanceID], IIf([tblEventException].[EventID] Is Null,IIf(([qec].[PeriodTypeID] Is Null) Or ([qec].[PeriodFreq] Is Null) Or ([qec].[InstanceID] Is Null), [qec].[EventStart],DateAdd([qec].[PeriodTypeID], [qec].[InstanceID]*[qec].[PeriodFreq],[qec].[EventStart])), IIf([tblEventException].[IsCanned],Null,[tblEventException].[InstanceDate])) AS EventDate, [qec].[EventDescrip], [qec].[Comment], [tblEventException].[IsCanned], [tblEventException].[InstanceComment], [qec].[EventStart], [qec].[RecurCount], [qec].[PeriodFreq], [ltPeriodType].[PeriodType] FROM ((qryEventCartesian As qec LEFT JOIN tblEventException ON ([qec].[InstanceID] = [tblEventException].[InstanceID]) AND ([qec].[EventID] = [tblEventException].[EventID])) LEFT JOIN ltPeriodType ON [qec].[PeriodTypeID] = [ltPeriodType].[PeriodTypeId]) RIGHT JOIN EventsTasksLink AS etl ON [qec].[EventID] = [etl].[EventID] WHERE ((([etl].[TaskID]) = 8) And (([qec].[IsImportant]) = True)) ORDER BY [qec].[EventID], [qec].[InstanceID];
  2.  
Error Received for Second Query
Expand|Select|Wrap|Line Numbers
  1. Run-time error '3061'
  2.  
  3. Too few parameters.  Expected 1.
  4.  
Dec 15 '11 #1
7 3136
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I've spent 30 minutes looking them both over, but I can't spot anything.

Just to make sure, you are getting the error on line 39, correct?
Dec 15 '11 #2
bunchaCoconuts
4 New Member
Yeah, it's on line 39.
Dec 15 '11 #3
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Well the "dummy" question it is then.
Are you sure you spelled the field IsImportant correct?

Is it a Yes/No type field?

This shouldn't matter but Ill ask anyway for lack of anything better to suggest: Does the field always have a value? I.e. its always either True or False, but never null.
Dec 15 '11 #4
bunchaCoconuts
4 New Member
I just double, and triple checked those things. It is typed correctly, it is a yes/no, and the default value is false.

Here is some more information that will hopefully help:

This database is split. I have a development environment and a production environment for this database. In the development environment, the data is stored on the local hard drive. The production environment stores the front-end on the local hard drive, but the data is stored on a network drive. While double checking these things you brought up, I realized the error only occurs in the production environment. So something about flipping the switch to use the data stored on the network drive (which is stored in the systemDbPath variable on line 5 in the code above) is causing this query to fail. I have no idea what that could be though.
Dec 15 '11 #5
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Im only asking again, cause it seems to be the most obvious explanation. You also checked that your production database has the field IsImportant?
Dec 15 '11 #6
bunchaCoconuts
4 New Member
... I had the stored query in both the front-end and the data file. The "IsImportant" field existed in the front-end, but not the data file. Thank you so much, sorry to waste your time on such a trivial issue.
Dec 15 '11 #7
NeoPa
32,556 Recognized Expert Moderator MVP
We see many such questions, so don't worry about that, but you may want to consider How to Debug SQL String (As that's always avoidable).

PS. You can scratch that. I'll leave this here as your question is a good illustration of exactly how it should be done. You, my friend, have absolutely nothing to reproach yourself for.
Dec 16 '11 #8

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

Similar topics

2
2966
by: Eric Woudenberg | last post by:
I just installed a Python 2.3.4 Windows binary on a friend's WinXP machine (because the latest Cygwin-provided Python 2.3 build leaves out the winsound module for some reason). When I try and...
0
1054
by: JeffLiu | last post by:
we developed a cgi application, and it's way slow. but we cannot figure it out to run it as fastcgi after many hours. any help?
1
2634
by: Yaroslav Bulatov | last post by:
> Hi, > > Equis Uno wrote: > > > I use meta-x shell to start a shell and then once I see a shell > > prompt I enter the python command and I get a well-behaved python > > shell inside of emacs....
1
1693
by: R D | last post by:
Hi, How do I get a *Windows* perl script to figure out what directory it is being run from/exists in? Cheers, R
1
4733
by: Hussain | last post by:
I have installed IIS 5 on Windows 2000 Server and have applied all the neccessary updates and patches. I am unable to run any ASP pages on the local server. I am able to view the HTML pages...
17
1916
by: John Salerno | last post by:
Ok, I've been browsing through the MySQLdb docs, and I *think* I know the kind of code I need to write (connect, cursor, manipulate data, commmit, etc. -- although I probably need to get more...
1
1261
by: Brett Wesoloski | last post by:
Ok in trying to figure out why I could not change teh Applicaiton.Run I found something else that is probably causing it. I left the program as Application.Run(new Login()); then in the...
8
1575
by: active | last post by:
I'm using a Process object to run cmd and I give it the text from a textbox. It only executes the first line i.e. the first command. Is there some way to tell cmd to keep executing. I could...
2
1709
by: Dirk | last post by:
Hello, I have a bunch of C programs that I've written and I was wondering if there was a program out there, preferably free, or a method of running these programs on my Windows Vista notebook? I...
4
1494
by: Miguel Valenzue | last post by:
I currently have two data sets named the following: Traffic_Data_01 Traffic_Data_02 (eventually this number will increase) I have another table named Traffic_Sets which lists the names of these...
0
7044
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
6908
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...
0
7045
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
7087
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...
1
6741
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...
0
6944
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...
0
5341
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,...
0
2995
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...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.