Compile Error Expected: List Seperator or ) (1 Viewer)

Geoff Codd

Registered User.
Local time
Today, 13:07
Joined
Mar 6, 2002
Messages
190
I have the following code

DoCmd.RunSQL ("INSERT INTO [tblDirect_Data_All_Utilities_(Apportioned)] ( Id, [Month], Apportioned, CO2 ) " _
& "SELECT [Points].[Id], DateAdd("d",-1,DateAdd(m,1,"01/" & Format(DateAdd("d",-15,[Date]),"mm/yyyy"))) AS [Month], " _
& "Int(([DataElectricity].[Units]/([Date]-(DateAdd("d",0,DMax("[Date]","DataElectricity","[Point_Id] = " " _
& "[Points].[Id] & " And [Direct] = 'D' And [Date] < #" & Format([Date],"mm/dd/yyyy") & "#")))))*Int(Format([Month],"d"))) " _
& "AS Apportioned, Int([Apportioned]*0.43) AS CO2 " _
& "FROM Points INNER JOIN DataElectricity ON [Points].[Id]=[DataElectricity].[Point_Id] " _
& "WHERE ((([DataElectricity].[Direct]) = "D")) " _
& "ORDER BY [Points].[Id], DateAdd("d",-1,DateAdd("m",1,"01/" & Format(DateAdd("d",-15,[Date]),"mm/yyyy")));")

I get a Compile Error Expected: List Seperator or ), at the section highlighted above.

Any idea, thanks in advance
Geoff
 

Jon K

Registered User.
Local time
Today, 13:07
Joined
May 22, 2002
Messages
2,209
You can't have double quotes inside each " .................. " _

Change the double quotes to single quotes e.g.
DateAdd('d',-1,DateAdd('m',1,'01/' & Format(DateAdd('d',-15,[Date]),'mm/yyyy'))) as [Month]
 

Mile-O

Back once again...
Local time
Today, 13:07
Joined
Dec 10, 2002
Messages
11,316
Jon K said:
You can't have double quotes inside each " .................. "

Yes you can. You just have to double them up.

i.e.


Code:
Dim strExample As String
strExample = "My name is ""Mile-O"""
MsgBox strExample

The message box would display My name is "Mile-O"
 

Jon K

Registered User.
Local time
Today, 13:07
Joined
May 22, 2002
Messages
2,209
Thanks for pointing this out, Mile-O.

In code two consecutive double quotes return one double quote, and two consecutive single quotes return one single quote.
 

Geoff Codd

Registered User.
Local time
Today, 13:07
Joined
Mar 6, 2002
Messages
190
Hi there again guys

I made the changes as suggested but now I am getting a syntax error

DoCmd.RunSQL ("INSERT INTO [tblDirect_Data_All_Utilities_(Apportioned)] ( Id, [Month], Apportioned, CO2 ) " _
& "SELECT [Points].[Id], DateAdd('d',-1,DateAdd(m,1,'01/' & Format(DateAdd('d',-15,[Date]),'mm/yyyy'))) " _
& "AS [Month], Int(([DataElectricity].[Units]/([Date]-(DateAdd('d',0,DMax('[Date]',[DataElectricity]',' " _
& "[Point_Id] = ' [Points].[Id] & ' And [Direct] = 'D' And [Date] < #' & Format([Date],'mm/dd/yyyy') & '#'))))) " _
& "*Int(Format([Month],'d'))) AS Apportioned, Int([Apportioned]*0.43) AS CO2 " _
& "FROM [Points] INNER JOIN [DataElectricity] ON [Points].[Id]=[DataElectricity].[Point_Id] " _
& "WHERE ((([DataElectricity].[Direct]) = 'D')) " _
& "ORDER BY [Points].[Id], DateAdd('d',-1,DateAdd('m',1,'01/' & Format(DateAdd('d',-15,[Date]),'mm/yyyy')));")

Any ideas, much appreciated
Thanks
Geoff
 

Jon K

Registered User.
Local time
Today, 13:07
Joined
May 22, 2002
Messages
2,209
My statement was over-simplified. I should have said:
In " ............." & ..... & " ........... " etc
don't put double quotes inside each " ............. "

DoCmd.RunSQL ("INSERT INTO [tblDirect_Data_All_Utilities_(Apportioned)] ( Id, [Month], Apportioned, CO2 ) " _
& "SELECT [Points].[Id], DateAdd('d',-1,DateAdd('m',1,'01/' & Format(DateAdd('d',-15,[Date]),'mm/yyyy'))) " _
& "AS [Month], Int(([DataElectricity].[Units]/([Date]-(DateAdd('d',0,DMax('[Date]','[DataElectricity]', " _
& "'[Point_Id] = '" & [Points].[Id] & "' And [Direct] = 'D' And [Date] < #" & Format([Date],'mm/dd/yyyy') & "'#'))))) " _
& "*Int(Format([Month],'d'))) AS Apportioned, Int([Apportioned]*0.43) AS CO2 " _
& "FROM [Points] INNER JOIN [DataElectricity] ON [Points].[Id]=[DataElectricity].[Point_Id] " _
& "WHERE ((([DataElectricity].[Direct]) = 'D')) " _
& "ORDER BY [Points].[Id], DateAdd('d',-1,DateAdd('m',1,'01/' & Format(DateAdd('d',-15,[Date]),'mm/yyyy')));")

Hope I've got it right this time.
 

Users who are viewing this thread

Top Bottom