Results 1 to 8 of 8
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Insert Into Statement Troubles

    Hi all,
    Can someone please assist me with the correct syntax in this statement?

    Code:
    Private Sub cmdCreateAccount_Click()
    
    
        DoCmd.SetWarnings False
        DoCmd.RunSQL "INSERT INTO tblAccount (AccountName, AccountTypeID, IsActive, IsBank, IsCreditCard,HasReward, AutoPayEnroled, OnLineAccessID, HasOnLineAccess, OpenBalance, OpenBalanceDate, AccountNumber, RoutingNumber, Memo) " & _
            "VALUES (" '" & AccountName & "'", " & cboAccountTypeID & ", "'" & IsActive & "'", " & IsBank & ", " & IsCreditCard & ", " & HasReward & ", " & AutoPayEnroled & ", " & OpenBalance & ", " & OpenBalanceDate & ", " & AccountNumber & ", " & RoutingNumber & ", " & Memo & ")"
        DoCmd.SetWarnings True
            
    End Sub
    AccountName is Txt, AccountTypeID is a cbo, IsActive is Chk, IsBlank is Chk, IsCreditCard is Chk, HasReward is Chk, AutoPayEnrolled is Chk, OnLineAccessID is Num, HasOnLineAccess is Chk, OpenBlanace is Currency, OpenBalanceDate is Date, AccountNumber is Txt, RoutingNumber is Txt, and Memo is Long Text!

    Thanks
    Dave

  2. #2
    SamL is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2021
    Location
    NJ
    Posts
    20
    Seems to me you're missing two values, OnLineAccessID and HasOnLineAccess. Are they necessary?


  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    I see i forgot them, will try that

  4. #4
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Still seems to have an error
    Runtime 3134
    Syntax Error in Insert Into Statement?

    Code:
    Private Sub cmdCreateAccount_Click()
        DoCmd.SetWarnings False
        DoCmd.RunSQL "INSERT INTO tblAccount (AccountName, AccountTypeID, IsActive, IsBank, IsCreditCard,HasReward, AutoPayEnroled, OnLineAccessID, HasOnLineAccess, OpenBalance, OpenBalanceDate, AccountNumber, RoutingNumber, Memo) " & _
            "VALUES (" '" & AccountName & "'", " & cboAccountTypeID & ", " & IsActive & ", " & IsBank & ", " & IsCreditCard & ", " & HasReward & ", " & AutoPayEnroled & ", " & cboInstitution & "," & HasOnLineAccess & "," & OpenBalance & ", " & OpenBalanceDate & ", " & AccountNumber & ", " & RoutingNumber & ", " & Memo & ")"
            
    End Sub

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Put it all into a string variable an debug.print it.
    That will show your errors, and if you still cannot see it post it back here.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Also note that date values need to be surrounded by # and simple text values by '. For help on what Welshgasman suggested:

    http://www.baldyweb.com/ImmediateWindow.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    thank you
    Appriciate it

  8. #8
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    See if this fixes the syntax:
    Code:
     "VALUES ('" & AccountName & "', " & cboAccountTypeID & ", '" & IsActive & "', " & IsBank & ", "
    Text delimiter syntax correction for AccountName and IsActive.
    If the various Isxxxxxx are text fields (like the letter Y or N), then you need the delimiters; if boolean fields, like True and False, none needed.
    In any case, there's inconsistency as you're showing text for IsActive, but not so for all the rest.
    Last edited by davegri; 10-25-2021 at 11:29 PM. Reason: added additional comments

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

Similar Threads

  1. Insert Into Statement Troubles
    By d9pierce1 in forum Programming
    Replies: 18
    Last Post: 10-21-2020, 12:50 PM
  2. Replies: 7
    Last Post: 05-10-2019, 10:40 PM
  3. Insert into with a WHERE statement
    By hazeleyre23 in forum Access
    Replies: 10
    Last Post: 04-06-2016, 08:28 AM
  4. INSERT statement
    By GraeagleBill in forum Programming
    Replies: 2
    Last Post: 03-29-2013, 12:53 PM
  5. Insert Into statement
    By TimMoffy in forum Programming
    Replies: 7
    Last Post: 07-13-2012, 07:10 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