Syntax Error

  • Thread starter auujxa2 via AccessMonster.com
  • Start date
A

auujxa2 via AccessMonster.com

Just when I think I'm getting good at SQL, I get humbled. I'm getting a
syntax error, and I know it's the last field, because if I remove it, it
works. And when I debg and hover over the last field, I get the path. So
it's just a matter of figuring out the correct placement of the quotations I
guess. Please help. Thank you in advance.

strSQL = "INSERT INTO MasterTbl ( When, Who, What, Where)" & _
" SELECT Now()" & "," & " """ & CurrentUser & """," & " " & "'S1'" &
" AS Str" & "," & " " & Application.CurrentProject.Path & ""

DoCmd.RunSQL strSQL
 
D

Douglas J. Steele

strSQL = "INSERT INTO MasterTbl ( When, Who, What, Where)" & _
" SELECT Now(),'" & CurrentUser & "', 'S1' & _
",'" & Application.CurrentProject.Path & "'"

Exagerated for clarity, that's

strSQL = "INSERT INTO MasterTbl ( When, Who, What, Where)" & _
" SELECT Now(),' " & CurrentUser & " ', 'S1' & _
",' " & Application.CurrentProject.Path & " ' "
 
A

auujxa2 via AccessMonster.com

It didn't work, so I did this instead: (i changed Where to Path)

strSQL = "INSERT INTO MasterTbl ( When, Who, What)" & _
" SELECT Now()" & "," & " """ & CurrentUser & """," & " " & "'S1'" &
" AS Str"

DoCmd.RunSQL strSQL

strSQL = " UPDATE [MasterTbl] SET [Path] = Application.CurrentProject.Path" &
_
" WHERE [Path] is Null"

DoCmd.RunSQL strSQL
strSQL = "INSERT INTO MasterTbl ( When, Who, What, Where)" & _
" SELECT Now(),'" & CurrentUser & "', 'S1' & _
",'" & Application.CurrentProject.Path & "'"

Exagerated for clarity, that's

strSQL = "INSERT INTO MasterTbl ( When, Who, What, Where)" & _
" SELECT Now(),' " & CurrentUser & " ', 'S1' & _
",' " & Application.CurrentProject.Path & " ' "
Just when I think I'm getting good at SQL, I get humbled. I'm getting a
syntax error, and I know it's the last field, because if I remove it, it
[quoted text clipped - 9 lines]
DoCmd.RunSQL strSQL
 
D

Douglas J. Steele

I'm absolutely shocked that that would work. I didn't think Jet knew
anything about Application.CurrentProject.Path, so I thought the query would
fail.

I just noticed a typo in my previous reply (which would explain why it
didn't work for you), but to be honest, I wouldn't use the SELECT style, I'd
use

strSQL = "INSERT INTO MasterTbl ( When, Who, What, Where)" & _
" VALUES (Now(),'" & CurrentUser & "', 'S1', '" & _
Application.CurrentProject.Path & "')"

Exagerated for clarity, that's

strSQL = "INSERT INTO MasterTbl ( When, Who, What, Where)" & _
" VALUES (Now(),' " & CurrentUser & " ', 'S1' , ' " & _
Application.CurrentProject.Path & " ' ) "

In case you care, there should have been a double quote between 'S1' and the
ampersand.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


auujxa2 via AccessMonster.com said:
It didn't work, so I did this instead: (i changed Where to Path)

strSQL = "INSERT INTO MasterTbl ( When, Who, What)" & _
" SELECT Now()" & "," & " """ & CurrentUser & """," & " " & "'S1'"
&
" AS Str"

DoCmd.RunSQL strSQL

strSQL = " UPDATE [MasterTbl] SET [Path] =
Application.CurrentProject.Path" &
_
" WHERE [Path] is Null"

DoCmd.RunSQL strSQL
strSQL = "INSERT INTO MasterTbl ( When, Who, What, Where)" & _
" SELECT Now(),'" & CurrentUser & "', 'S1' & _
",'" & Application.CurrentProject.Path & "'"

Exagerated for clarity, that's

strSQL = "INSERT INTO MasterTbl ( When, Who, What, Where)" & _
" SELECT Now(),' " & CurrentUser & " ', 'S1' & _
",' " & Application.CurrentProject.Path & " ' "
Just when I think I'm getting good at SQL, I get humbled. I'm getting a
syntax error, and I know it's the last field, because if I remove it, it
[quoted text clipped - 9 lines]
DoCmd.RunSQL strSQL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Select Case - SQL 2
SQL Syntax Error 1
List Box 11
SQL Question 3
SQL Update and NOW 3
return without gosub error 0
Powerpoint Ink Reacts Different in Different places 0
SQL Syntax Error - UPDATE command 1

Top