Results 1 to 3 of 3
  1. #1
    pablo40 is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Poland
    Posts
    6

    VBA uses dot for decimals but sql uses comma which leads to syntax error in UPDATE query.

    Hello everyone,

    This is my first post on this forum and I sincerely hope someone can come up with solution to the problem I am facing.


    I have the following issue:
    - in VBA when defining a value to a variable (for example 10.5) decimals go with a dot (not comma), comma is not accepted as putting comma causes an error
    - however when embedding such value in SQL statement a dot causes an error as SQL only accepts commas.
    - I cannot replace dot with a comma when defining a value like for example 10.5 and changing it to 10,5 as it causes error


    Interestingly there is no such conflict in Access 2013 (and the below query works) but in Access 2010 version the below query does not work.
    I tried converting 10.5 to text and then 'wrapping up' this text with Cdbl(text). But it does not work.
    Below is the code. And I would really appreciate if someone could help me on that.

    Sub test()

    'THE FOLLOWING WORKS WITH MSACCESS 2013 BUT DOES NOT WORK WITH MSACCESS 2010!!
    'CONSEQUENTLY THE SAME QUERY BEHAVES DIFFERENTLY IN TWO ACCESS VERSIONS

    poziom_agregacji = 2


    SumaCostChargeIn = 345.2 'double number must have dots, comma is not accepted as if used then COMPILE ERROR IS PRODUCED
    strsql = "UPDATE tblmastertable SET tblmastertable.costchargein=" & SumaCostChargeIn & " WHERE (((tblmastertable.[Levell])=" & poziom_agregacji - 1 & ")" _
    & "AND ((tblmastertable.[ID])=" & 2 & ") AND ((tblmastertable.[treeid])=" & 255 & "));"

    With CurrentDb 'is run for the first time it would be better to check to see if the
    .QueryDefs.Delete ("AktualizujPodsumy") ' querydef exists and then delete it
    Set qdfNew = .CreateQueryDef("AktualizujPodsumy", strsql) ' THIS THROWS SYNTAX ERROR IN UPDATE STATEMENT BECAUSE SQL USES COMMA AND ON THE OTHER HAND DOUBLE NUMBER USES DOTS
    .Close
    End With
    DoCmd.OpenQuery "AktualizujPodsumy", acViewNormal, acViewPreview

    End Sub

  2. #2
    pablo40 is offline Novice
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Poland
    Posts
    6
    I've managed to solve this problem!!
    The solution is to replace SumaCostChargeIn with x where:

    x = Replace(CStr(SumaCostChargeIn), ",", ".")

    strsql = "UPDATE tblmastertable SET tblmastertable.costchargein= " & x & " WHERE (((tblmastertable.[Levell])=" & poziom_agregacji - 1 & ")" _
    & "AND ((tblmastertable.[ID])=" & 2 & ") AND ((tblmastertable.[treeid])=" & 255 & "));"


    I hope someone will find it useful!

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Thanks for posting your solution, and welcome to the site!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Syntax error (comma) in query expression
    By Access_Novice in forum Queries
    Replies: 4
    Last Post: 09-10-2014, 04:14 PM
  2. Syntax Error 3144 in SQL Update Query.
    By Phred in forum Programming
    Replies: 4
    Last Post: 03-02-2012, 02:39 PM
  3. Replies: 1
    Last Post: 11-30-2011, 01:13 AM
  4. Syntax error (comma) in query expression?
    By TheWolfster in forum Queries
    Replies: 5
    Last Post: 05-10-2010, 12:02 PM
  5. Syntax error (comma) in query expression
    By KLynch0803 in forum Programming
    Replies: 3
    Last Post: 01-18-2010, 03:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums