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 -
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim strSQL As String
-
-
Set db = OpenDatabase(systemDbPath & "Data.accdb")
-
-
If ImportantDatesOnly = True Then
-
strSQL = "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]) = " & TaskID & ") And " & _
-
"(([qec].[IsImportant]) = True)) ORDER BY [qec].[EventID], [qec].[InstanceID];"
-
Else
-
strSQL = "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] = " & TaskID & _
-
" ORDER BY [qec].[EventID], [qec].[InstanceID];"
-
End If
-
-
Set rs = db.OpenRecordset(strSQL)
-
Calculated Query that Works -
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];
-
Calculated Query that Doesn't Work -
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];
-
Error Received for Second Query -
Run-time error '3061'
-
-
Too few parameters. Expected 1.
-
7 3136
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?
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.
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.
Im only asking again, cause it seems to be the most obvious explanation. You also checked that your production database has the field IsImportant?
... 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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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?
|
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....
|
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
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |