Solved

Syntax error (missing operator) SQL

Posted on 2010-11-17
4
291 Views
Last Modified: 2012-05-10
Experts,

I'm trying run the SQL below in the on open event, and set it equal to a graphs's row source. I copied and pasted it from a query that works, but I'm getting the attached syntax error (missing operator)  when I try to run it from the on open event.

Thanks,
James
strSQL2 = "SELECT (Format([MDate],'mmm'' '''yy')) AS Expr1, Avg(qryMAIN_Patient_WtHtBMI_calc3.BMI4A_P) AS AvgOfBMI4A_P " & _

"FROM qryMAIN_Patient_WtHtBMI_calc3 " & _

"GROUP BY(Format([MDate], 'mmm'' '''yy')), (Year([MDate]) * 12 + Month([MDate]) - 1) " & _

"ORDER BY (Year([MDate])*12+Month([MDate])-1)"

Open in new window

error.PNG
0
Comment
Question by:jdallain
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
Comment Utility
Try this code

strSQL2 = "SELECT (Format([MDate],'''mmm''' '''yy''')) AS Expr1, Avg(qryMAIN_Patient_WtHtBMI_calc3.BMI4A_P) AS AvgOfBMI4A_P " & _
"FROM qryMAIN_Patient_WtHtBMI_calc3 " & _
"GROUP BY(Format([MDate], '''mmm''' '''yy''')), (Year([MDate]) * 12 + Month([MDate]) - 1) " & _
"ORDER BY (Year([MDate])*12+Month([MDate])-1)"

Open in new window


Need more apostrophe

Raj
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
what about this:

strSQL2 = "SELECT (Format([MDate],'mmm yy')) AS Expr1
, Avg(qryMAIN_Patient_WtHtBMI_calc3.BMI4A_P) AS AvgOfBMI4A_P " & _
"FROM qryMAIN_Patient_WtHtBMI_calc3 " & _
"GROUP BY(Format([MDate], 'mmm yy')), (Year([MDate]) * 12 + Month([MDate]) - 1) " & _
"ORDER BY (Year([MDate])*12+Month([MDate])-1)"

Open in new window

0
 
LVL 23

Expert Comment

by:Rajkumar Gs
Comment Utility
Oh! I think, angelIII provided right solution

Raj
0
 

Author Closing Comment

by:jdallain
Comment Utility
Thanks  a lot fellows!

James
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now