Results 1 to 4 of 4
  1. #1
    polisasimo is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    9

    Null Value Insert - Syntax Error with Nz()


    Any help on what is throwing a syntax error here would be greatly appreciated.

    In this case the Me.TextBase is Null

    SQL = "INSERT INTO SomeTable(Base, Access)" & " VALUES(" & Nz(Me.TextBase, Null) & ", '" & Me.TextAccess & "')"

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Why bother with Nz since you are using Null as the alternate value anyway? The purpose of Nz is to return a value other than Null.

    Is Base a number type field?

    Don't see anything wrong with syntax. The first concatenation is unnecessary but shouldn't hurt.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Try putting the Null in quotation marks, because you want to return the string "Null", not an actual Null value:

    SQL = "INSERT INTO SomeTable(Base, Access)" & " VALUES(" & Nz(Me.TextBase, "Null") & ", '" & Me.TextAccess & "')"

    e.g., you want the SQL to look something like this:

    INSERT INTO SomeTable(Base, Access) VALUES( Null, 'Some String')

    HTH

    John

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    If you want text "Null" instead of actual Null then the code needs apostrophe delimiters:

    SQL = "INSERT INTO SomeTable(Base, Access) VALUES('" & Nz(Me.TextBase, "Null") & "', '" & Me.TextAccess & "')"

    Then the compiled SQL would be like:

    INSERT INTO SomeTable(Base, Access) VALUES('Null', 'Some String')

    But if Base is number type field, cannot save text "Null".
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  2. Replies: 5
    Last Post: 03-30-2012, 09:00 AM
  3. INSERT INTO Syntax Error
    By eww in forum Programming
    Replies: 1
    Last Post: 04-06-2011, 10:28 AM
  4. SQL INSERT INTO Date Syntax Error
    By tuna in forum Programming
    Replies: 5
    Last Post: 08-10-2010, 06:17 AM
  5. Syntax Error In Insert Into Statement
    By frankvfox in forum Queries
    Replies: 1
    Last Post: 09-09-2008, 12:35 PM

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