472,124 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,124 software developers and data experts.

docmd.runsql update problem

Hi,

i try to execute an update query from within a form, but i get the message:
run time error '3144'. Syntax error on the update statement
when i try something like this:
DoCmd.RunSQL "UPDATE tblKlant " & _
"SET tblKlant.Bedrag = tblKlant.Bedrag + 10.96" & _
" WHERE tblKlant.[Klant-id] = forms![Form1]![Klant-id]"
everything works fine. If i change it to the following:
Dim ntest As Double
ntest = 10.96
DoCmd.RunSQL "UPDATE tblKlant " & _
"SET tblKlant.Bedrag = tblKlant.Bedrag + " & ntest & _
" WHERE tblKlant.[Klant-id] = forms![Form1]![Klant-id]"
i get the error. If i change the value of ntest to 10, there's no problem...

I don't understand this, can anyone help?

Thnx.
Rogier
Nov 12 '05 #1
4 10068
Try using Debug.Print to send the whole SQL statement to the Debug window,
and post it again, just to see what the result is coming out as. I can't see
any reason there that it would fail.

Mike Storr
www.veraccess.com

"Rotsj" <r.**********@home.nl> wrote in message
news:f4**************************@posting.google.c om...
Hi,

i try to execute an update query from within a form, but i get the message: run time error '3144'. Syntax error on the update statement
when i try something like this:
DoCmd.RunSQL "UPDATE tblKlant " & _
"SET tblKlant.Bedrag = tblKlant.Bedrag + 10.96" & _
" WHERE tblKlant.[Klant-id] = forms![Form1]![Klant-id]"
everything works fine. If i change it to the following:
Dim ntest As Double
ntest = 10.96
DoCmd.RunSQL "UPDATE tblKlant " & _
"SET tblKlant.Bedrag = tblKlant.Bedrag + " & ntest & _
" WHERE tblKlant.[Klant-id] = forms![Form1]![Klant-id]"
i get the error. If i change the value of ntest to 10, there's no problem...
I don't understand this, can anyone help?

Thnx.
Rogier

Nov 12 '05 #2
Hello Mike,

thanks for your advice, now i know what goes wrong:
ntestje = 10.5

debug.Print "UPDATE tblKlant " & _
"SET tblKlant.Bedrag = tblKlant.Bedrag + " &
ntestje & _
" WHERE tblKlant.[Klant-id] =
forms![Form1]![Klant-id]"
UPDATE tblKlant SET tblKlant.Bedrag = tblKlant.Bedrag + 10,5 WHERE
tblKlant.[Klant-id] = forms![Form1]![Klant-id]
as you see, instead of 10.5, it translates into 10,5. Do you know what
to do to solve this?

Thanks!
Rogier

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
The only reason I can think of why it would use a comma is because of the
Regional settings of the computer, but this should only be a format and not
change the data.
My only suggestions are to check the settings in control panel for decimal
format, try using Single instead of Double, build the query using design
view - then switch to SQL view and copy and paste the SQL into your code and
see if it looks any different - or works any different. Beyond that I'm out
of ideas.
Mike Storr
www.veraccess.com

"rogier knipscheer" <r.**********@home.nl> wrote in message
news:40***********************@news.frii.net...
Hello Mike,

thanks for your advice, now i know what goes wrong:
ntestje = 10.5

debug.Print "UPDATE tblKlant " & _
"SET tblKlant.Bedrag = tblKlant.Bedrag + " &
ntestje & _
" WHERE tblKlant.[Klant-id] =
forms![Form1]![Klant-id]"
UPDATE tblKlant SET tblKlant.Bedrag = tblKlant.Bedrag + 10,5 WHERE
tblKlant.[Klant-id] = forms![Form1]![Klant-id]
as you see, instead of 10.5, it translates into 10,5. Do you know what
to do to solve this?

Thanks!
Rogier

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #4
"rogier knipscheer" <r.**********@home.nl> wrote in message
news:40***********************@news.frii.net...
Hello Mike,

thanks for your advice, now i know what goes wrong:
ntestje = 10.5

debug.Print "UPDATE tblKlant " & _
"SET tblKlant.Bedrag = tblKlant.Bedrag + " &
ntestje & _
" WHERE tblKlant.[Klant-id] =
forms![Form1]![Klant-id]"
UPDATE tblKlant SET tblKlant.Bedrag = tblKlant.Bedrag + 10,5 WHERE
tblKlant.[Klant-id] = forms![Form1]![Klant-id]
as you see, instead of 10.5, it translates into 10,5. Do you know what
to do to solve this?

Thanks!
Rogier

Rogier
Consider also any thousand separator (I don't know if you write numbers like
the Germans). If you have a string like 1.724,5 (meaning one thousand seven
hundred and twenty-four and a half) you must first get rid of the "." for
the thousands and then replace the "," with "."

If you have Access 2000 or above, you can use the Replace function

strNumber = Replace(Format(varNumber), ",", ".")

Will return 1724.5

PS
There are other ways to execute SQL other than DoCmd.RunSQL. You could
write a function which would tell you how many records had been updated by
the change (perhaps this should always be one).

Set dbs = CurrentDb
dbs.Execute strSQL, dbFailOnError
Msgbox dbs.RecordsAffected & " record(s) updated"
Set dbs = Nothing


Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jim | last post: by
reply views Thread by Andy | last post: by
3 posts views Thread by Pathfinder | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.