Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a VBA query which errors say

Status
Not open for further replies.

vix666

IS-IT--Management
Jul 17, 2003
63
AU
I have a VBA query which errors saying "Missing operator in query expression 'Format([Date],""mm"") AS Month'. Any ideas what is missing as I keep trying different things and im not getting anywhere?

Thanks in advance

Vicky

strSQL = "SELECT Count([Complaints Table].Counter) AS CountOfCounter, [Complaints Table].[Type of Complaint], Format([Date],""mm"") AS Month" & _
" FROM [Complaints Table]" & _
" WHERE ((([Complaints Table].Date) Between " & _
" [Forms]![Print Request between dates]![sdate]" & _
" And [Forms]![Print Request between dates]![edate])" & _
" AND (([Complaints Table].[Attributable to Company])=""epco""))" & _

" GROUP BY [Complaints Table].[Type of Complaint], Format([Date],""mm"")" & _

" ORDER BY [Type of Complaint], Format([Date],""mm"")As Month; "
 
Is there a space missing before the "As Month"?

ORDER BY [Type of Complaint], Format([Date],""mm"")As Month
 
There wasnt a space but I have changed this and there is still the same error, any other ideas?

Thanks for the help

Vicky
 
Vicky,

Have you tried running it with only single " marks in your code?

Code:
ORDER BY [Type of Complaint], Format([Date],"mm")As Month

I'm only guessing here though.


Leigh Moore
Solutions 4 MS Office Ltd
 
Yep i've tried single " marks and that errors on the marks saying about is doesnt like being the end of the sentence.
Ive tried ' marks and it doesnt work :(

Thanks for the suggestion though

Any other ideas

Vicky
 
Hi vicky,

try this:

strSQL = "SELECT Count([Complaints Table].Counter) AS CountOfCounter, [Complaints Table].[Type of Complaint], Format([Date],""mm"") AS Month" & _
" FROM [Complaints Table]" & _
" WHERE ((([Complaints Table].Date) Between " & _
" [Forms]![Print Request between dates]![sdate]" & _
" And [Forms]![Print Request between dates]![edate])" & _
" AND (([Complaints Table].[Attributable to Company])=""epco""))" & _

" GROUP BY [Complaints Table].[Type of Complaint], month" & _

" ORDER BY [Type of Complaint], Month "

regards,
nicsin
 
nicsin has it right for the ORDER BY - Take out the "As Month" (completely missed that before).

I think the group by was okay in your first post.

GROUP BY [Complaints Table].[Type of Complaint], Format([Date],""mm"")

 
I now get another error saying "you tried to execute a query that doesnt include the specified expression 'Format([Date], ""mm"") as part of an aggregate function.

Any ideas?

Thanks for all the help

Vicky
 
Did you use the alias, ie "month" or 'Format([Date], ""mm"") at the GROUP BY clause? Try using the other instead.
 
I thought i'd already tried that but I tried it again and it stopped erroring, now i get another error :(
It says "too few parameters expected 3", the code is below


strSQL = "SELECT Count([Complaints Table].Counter) AS CountOfCounter, [Complaints Table].[Type of Complaint], Format([Date],""mm"") AS Month" & _
" FROM [Complaints Table]" & _
" WHERE ((([Complaints Table].Date) Between " & _
" [Forms]![Print Request between dates]![sdate]" & _
" And [Forms]![Print Request between dates]![edate])" & _
" AND (([Complaints Table].[Attributable to Company])=""epco""))" & _
" GROUP BY [Complaints Table].[Type of Complaint], Format([Date],""mm"")" & _
" ORDER BY [Type of Complaint], Month; "
 
Insert # before and after dates like:

between #date1# and #date2#
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top