Run Time Error 3131(NEWBIE NEEDS ASSISTANCE)

REAbernathy

New member
Local time
Today, 14:54
Joined
Aug 16, 2012
Messages
3
I am getting a Run-Time Error 3131
Syntax Error is From clause
Here is the code that I am trying to run and i cant figure this out.......PLEASE Help...

Dim strSQL As String

strSQL = " SELECT FirmNumber, NumberofAccounts, EmployeeID, ErrorCodeDescription, " & _
" ErrorCodesandCorrections , Agreements, TypeofCommunication, Time, OpenedDate FROM TrackingSystem3 " & _
" INTO TempReport_Table from TrackingSystem3 " & _
" WHERE NumberofAccounts = (SELECT Max (NumberofAccounts) from TrackingSystem3) And Time = (SELECT Max (Time) from TrackingSystem3); "

DoCmd****nSQL strSQL
 
Last edited:
From what I can make of your SQL is that You have TableMakeQuery, it errors because you have an extra FROM. It should be something like:
Code:
strSQL = "SELECT FirmNumber, NumberofAccounts, EmployeeID, ErrorCodeDescription, ErrorCodesandCorrections , Agreements, TypeofCommunication, Time, OpenedDate " & _
'[COLOR="red"]FROM TrackingSystem3 " & _[/COLOR]" 'this should not be here
"INTO TempReport_Table " & _
"FROM TrackingSystem3 " & _
"WHERE NumberofAccounts = (SELECT Max (NumberofAccounts) from TrackingSystem3) And Time = (SELECT Max (Time) from TrackingSystem3);"
As a note to building SQL strings, I prefer the seperating spaces at the end of a line (makes it easier to check). I removed all spaces at the start of the line as you had them on start and end of a line.
 
Last edited:
PeterF

Thanks so much PeterF for your assistance it really helped out alot but let me ask you another question. Would it be easier to just call the query like this.

DoCmd.SetWarnings False
DoCmd.OpenQuery "TrackingSystem3 Query"
DoCmd.SetWarnings True

Just wondering? Also I am having a problem with Looping can you assist me with this as well? I wont send you anything about my loop until you respond. And again Thank You for your assistance.
 
Last edited:
As this is an action query "DoCmd.OpenQuery" can be replaced by "CurrentDB.Execute" and you don't need to disable / enable warnings. This way you don't have the risk that the warnings stay off.

I'm not clairvoyant I can't tell you if I'm able to help with your loopint problem (or have the time). But this is a forum and together we share a whelm of knowledge.
 

Users who are viewing this thread

Back
Top Bottom