Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 14th, 2004, 05:15 PM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Coldendus Send a message via Yahoo to Coldendus
Default HELP!!! Jet SQL: Error (80040e14)

I'm trying to re-create some Access queries as ADO recordsets via the Jet Provider.

I was under the impression that I could copy the SQL code from the query itself and use that as my SQL string. Apparantly not.

I continue to get this error message...

"Syntax error (missing operator) in query expression."

whenever I use aggregate functions such as
Datediff() or Sum(IIf(X,1,0))

(I'm trying to avoid TRANSFORM and PIVOT but I may have to use them.)

Anyone have any ideas?

Reply With Quote
  #2 (permalink)  
Old December 14th, 2004, 05:25 PM
Authorized User
 
Join Date: Jul 2004
Location: clapton-in-gordano, n.somerset, United Kingdom.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

I have no idea why, but when operating in ADO mode I find that Application.Execute works whereas DoCmd.RunSql doesn't. I know they should be the same, but...

Generally speaking your error message comes from the fact that the sql string must be ENTIRELY a string, Copy your formula to the group and maybe extra eyes will spot something you've missed. It's probably just a missing set of "".

All the best

Alan Thomas

Reply With Quote
  #3 (permalink)  
Old December 14th, 2004, 05:33 PM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Coldendus Send a message via Yahoo to Coldendus
Default

This is the code I am working with...
‘~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
‘Start of Code
‘~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Report_Open(Cancel As Integer)
    Dim cnnReport As New ADODB.Connection
    Dim rstReport As New ADODB.Recordset
    With cnnReport
        .Provider = strProvider
        .Properties("Data Source") = strDataSource
        .Properties("Jet OLEDB:Database Password") = strPropDatabasePassword
        .Open
    End With

strSQL = "SELECT FormatDateTime([dtmExport],2) AS ExportDte,"
strSQL = strSQL & "DateDiff('d', tbl002TaskTracking.dtmExport ,#" & Date & "#) AS DaysOut,"
strSQL = strSQL & "Sum(IIf([bytTaskId]=1,1,0)) AS [Total],"
strSQL = strSQL & "Sum(IIf([strTaskGroup]='ICO-ST' And [bytTaskId]=1,1,0)) AS [Total ST],"
strSQL = strSQL & "Sum(IIf([strTaskGroup]='ICO-EX' And [bytTaskId]=1,1,0)) AS [Total EX],"
‘~~~~~~~~~~~~~~~~
‘Why are there additional parenthesis around the sum function you may ask.
‘ I have NO idea. At this point I am copying the SQL directly from the query window in Access
‘~~~~~~~~~~~~~~~~
strSQL = strSQL & "(Sum(IIf([bytTaskId]=1 And [strtaskstatus]<>'Complete',1,0))) AS [Phase1],"
strSQL = strSQL & "(Sum(IIf([bytTaskId]=2 And [strtaskstatus]<>'Complete',1,0))) AS [Phase2],"
strSQL = strSQL & "(Sum(IIf([bytTaskId]=3 And [strtaskstatus]<>'Complete',1,0))) AS [Phase3],"
strSQL = strSQL & "(Sum(IIf([bytTaskId]=4 And [strtaskstatus]<>'Complete',1,0))) AS [Phase4],"
strSQL = strSQL & "(Sum(IIf([bytTaskId]=5 And [strtaskstatus]<>'Complete',1,0))) AS [Phase5],"
strSQL = strSQL & "(Sum(IIf([bytTaskId]=6 And [strtaskstatus]<>'Complete',1,0))) AS [Phase6],"
strSQL = strSQL & "(Sum(IIf([bytTaskId]=7 And [strtaskstatus]<>'Complete',1,0))) AS [Phase7],"
strSQL = strSQL & "(Sum(IIf([bytTaskId]=8 And [strtaskstatus]<>'Complete',1,0))) AS [Phase8],"
strSQL = strSQL & "(Sum(IIf([bytTaskId]=9 And [strtaskstatus]<>'Complete',1,0))) AS [Phase9],"
strSQL = strSQL & "(Sum(IIf([bytTaskId]=10 And [strtaskstatus]<>'Complete',1,0))) AS [Phase10],"
strSQL = strSQL & "(Sum(IIf([bytTaskId]<>11 And [strtaskstatus]<>'Complete',1,0))) AS [Phase11] "
strSQL = strSQL & "FROM tbl002TaskTracking "
strSQL = strSQL & "GROUP BY FormatDateTime([dtmExport],2), "
strSQL = strSQL & "DateDiff('d',[dtmExport],#" & Date & "#) "
‘~~~~~~~~~~~~~~~~~
‘Again below Access seems to LOVE parenthesis
‘~~~~~~~~~~~~~~~~~
strSQL = strSQL & "HAVING ((((Sum(IIf([bytTaskId]<>11 And [strtaskstatus]<>'Complete',1,0))))<>0)) "
strSQL = Replace(strSQL, "'", "''")

    With rstReport
        Set .ActiveConnection = cnnReport
        .CursorType = adOpenStatic
        .CursorLocation = adUseClient
        .LockType = adLockReadOnly
        .Open strSQL
    End With
End Sub
‘~~~~~~~~~~~~~~~~~~~~
‘End of Code
‘~~~~~~~~~~~~~~~~~~~~
 I've also tried...
strSQL = "TRANSFORM Count(tbl001Detail.lngID) AS CountOflngLoanID "
strSQL = strSQL & "SELECT Format([tbl001Detail].[dtmExport],"yyyy-mm-dd") AS [Date] "
strSQL = strSQL & "FROM tbl001Detail "
strSQL = strSQL & "INNER JOIN tbl002TaskTracking "
strSQL = strSQL & "ON tbl001Detail.lngID = tbl002TaskTracking.lngID "
strSQL = strSQL & "WHERE tbl002TaskTracking.strTaskStatus <> 'Complete' "
strSQL = strSQL & "AND tbl002TaskTracking.strTaskStatus <> 'cawd' "
strSQL = strSQL & "GROUP BY Format([tbl001Detail].[dtmExport],'yyyy-mm-dd') "
strSQL = strSQL & "PIVOT tbl002TaskTracking.strTaskName
strSQL = strSQL & "IN ('Phase1',’Phase2’,’Phase3’,’Phase4’, Phase5','Phase6','Phase7','Phase8','Phase9')
strSQL = Replace(strSQL, "'", "''")


I always seem to be getting my error in ANY aggregate functions within the select statement, however I’m not sure how to get around it since this is a summary. All functions involving my date seem to be going awry.
Reply With Quote
  #4 (permalink)  
Old December 14th, 2004, 08:12 PM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Coldendus Send a message via Yahoo to Coldendus
Default

Apparantly I can use date functions that do not include text strings...

BAD...
DateDiff('d',date1,date2)
Format(Date1,'yyyy-mm-dd')

OK
FormatDateTime(date1,2)

If anyone knows a way around this limitation or even what the specific limitation is I would appreciate knowing about it

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MY SQL to ACCESS 80040e14' lancom Classic ASP Databases 1 December 18th, 2006 08:56 AM
SQL Server error '80040e14' JA1 SQL Server ASP 1 April 11th, 2006 09:26 AM
Microsoft JET Database Engine error '80040e14' aprnip Classic ASP Databases 6 December 10th, 2005 07:36 AM
Microsoft JET Database Engine error '80040e14' aprnip Classic ASP Databases 2 November 15th, 2004 02:06 AM
error '80040e14'... only for some not all!?? dancrocker Classic ASP Databases 18 June 10th, 2004 11:15 AM



All times are GMT -4. The time now is 07:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.