Results 1 to 5 of 5
  1. #1
    programmingnewby is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jul 2019
    Posts
    9

    SYNTAX ERROR 3131 - Adding information to table via form

    Please see my attached code below, I am constantly receiving a Run-time error '3134': Syntax Error in INSERT INTO statement.
    Attaching an image of my drivers subform fields;
    End goal: use form to enter information into table (Drivers Information)Click image for larger version. 

Name:	DRIVERS SUBMFORM FIELDS.jpg 
Views:	8 
Size:	275.5 KB 
ID:	39054


    Private Sub cmdAdd_Click()
    'add data to table
    CurrentDb.Execute "INSERT INTO drivers information(Driver Last Name, Driver First Name, [DOB], Drivers CDL, CDL Expiration, CDL State, MC Recieved, MC Expiration, Company, Hire Date, Social Security, Drug Test Date) " & _
    " VALUES(" & Me.txtSocial & ", '" & Me.txtFirst & "','" & Me.txtLast & "','" & Me.txtDOB & "','" & Me.txtCDL & "','" & Me.txtCDLEXP & "','" & _


    Me.txtMC & "','" & Me.txtMCEXP & "','" & Me.txtCMP & "','" & Me.txtHIRE & "','" & Me.txtSocial & "','" & Me.txtDrug & "')"


    'refresh data in list on form
    frmDriverSub.Form.Requery
    End Sub

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Right off the bat I see that the first value you are trying to add is "Drive Last Name", but in the "VALUES" clause, you are missing the required Text qualifiers around that entry, i.e.
    Code:
    " VALUES(" & Me.txtSocial & ", '"
    should be:
    Code:
    " VALUES('" & Me.txtSocial & "', '"
    There may be other errors, but that is the first one I see. I would recommend creating that whole line in a String. Then you can easily use a MsgBox to check to see if you have written it correctly, i.e.
    Code:
    Dim strSQL as String
    strSQL =  "INSERT INTO drivers information(... "
    MsgBox strSQL  'temporary, can remove this line when working
    CurrentDb.Execute strSQL

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    dont use SQL, use a query. They wont get the syntax wrong.
    but
    if its a string, you must use quotes. I suggest txtSocial:
    VALUES('" & Me.txtSocial & "',

  4. #4
    programmingnewby is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jul 2019
    Posts
    9
    Thank you! Already solved issue #1 with your reply.
    Now I messed up something new... Click image for larger version. 

Name:	NEW ERROR.jpg 
Views:	7 
Size:	19.9 KB 
ID:	39055

    If you are interested thank you for the help, if not I will return to reading!

  5. #5
    programmingnewby is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Jul 2019
    Posts
    9
    Thank you was just missing a space!

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

Similar Threads

  1. DAO ALTER TABLE syntax error
    By GraeagleBill in forum Programming
    Replies: 7
    Last Post: 03-15-2019, 05:03 PM
  2. Replies: 2
    Last Post: 06-08-2014, 10:23 AM
  3. Replies: 13
    Last Post: 05-30-2014, 04:07 PM
  4. Alter Table syntax error
    By markjkubicki in forum Programming
    Replies: 1
    Last Post: 02-06-2012, 05:43 PM
  5. Syntax error when Adding Buttons
    By Barry Golten in forum Access
    Replies: 7
    Last Post: 08-03-2011, 07:56 AM

Tags for this Thread

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