Re: sql syntax error



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I just noticed in your original post that there isn't a space between
INTO and the name of your table - please insert one.

The red highlight is a VBA error indication, not a SQL syntax error.
Therefore, the string probably isn't properly formatted for VBA. My
guess is that you don't have line-end indicators. Try this string [this
assumes the ChangeDate's Default is set to =Date()]:

SQL = "INSERT INTO lkpStatusChanges (SiteRef, [status], " & _
"ChangedBy) VALUES(" & iRef & ",'" & sStatus & _
"','" & sBy "')"

Note the & _ at the end of the line - this indicates the string
continues on the next line.

HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSdu7wIechKqOuFEgEQLCtACdE5bVDdMVcqJ98QhOzI/ecrIQn/AAoMEu
kJ+Qiq3BuQ38TZ5UmyOgFOAo
=8eF+
-----END PGP SIGNATURE-----


paul wrote:
Sorry, to be clear the following line is highlighted in red before
i've run anything so no even getting to the debug stage. dToday is a
date formatted, with #'s using the SQLDate function i found on this
group.

Ive tried taking the date out of the insert statement and setting the
default table value to Date but the line is still hightlighted red!

Any other ideas?

Thanks again
Paul


On Apr 3, 5:28 pm, MGFoster <m...@xxxxxxxxxxx> wrote:
paul wrote:
Hi im getting a syntax error on the following and cant figure out
where i've gone wrong, any suggestions?
SQL = "insert intolkpStatusChanges
(SiteRef,status,ChangeDate,ChangedBy) values (" & iRef & ",'" &
sStatus & "'," & dToday & ",'" & sBy "')"
DoCmd.RunSQL sSQL
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You may want to put [] brackets around the word status since it is a SQL
reserved word; also put # delimiters around the date value, though it
should not be causing a problem.

... "',#" & dToday & "#,'" ....

And, use the newer Execute method:

CurrentDb.Execute sSQL, dbFailOnError

For the ChangeDate you could set the table Default values to =Date() or
=Now(). That way you wouldn't have to include it in an INSERT command.
Unfortunately, Access won't allow the CurrentUser() function in the
Default for ChangedBy - it doesn't recognize its own built-in function!

HTH,
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBSdY5NIechKqOuFEgEQKLUQCfWsBkAoaEZF5Wi0LSBTg3UEaZyxkAnR6u
yHvKBF6HujpGtIZS8AlKCo+N
=ogDO
-----END PGP SIGNATURE-----

.



Relevant Pages

  • Re: Need help with regular expression
    ... Hash: SHA1 ... Lars Enderin schreef: ... I'm using String.matches(regex) to find out if the string matches ...
    (comp.lang.java.help)
  • Re: MD5 Hash with single quote = grief in dao.findfirst
    ... > Hundreds of assumption cells combined into one 16 character Hash. ... But if the Hash string contains a single ... I do not get a SQL error. ... > I have a small function to replace a single quote with two single quotes ...
    (microsoft.public.access.modulesdaovba)
  • MD5 Hash with single quote = grief in dao.findfirst
    ... I know when you need to create a query string and the data contains a single ... quote, you must double the quote as an escape sequence. ... Hundreds of assumption cells combined into one 16 character Hash. ... I build the criteria SQL string. ...
    (microsoft.public.access.modulesdaovba)
  • Re: MD5 Hash with single quote = grief in dao.findfirst
    ... I set the Hash Field size to Text 20. ... I do not get a SQL error. ... >> I have a small function to replace a single quote with two single quotes ... >> I build the criteria SQL string. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Testing to see if a query is open
    ... Hash: SHA1 ... Function IsOpen(strName As String, _ ... ' Get the current state of the named object ...
    (microsoft.public.access.queries)