dcsimg
Results 1 to 4 of 4
  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    12

    Resolved [RESOLVED] Runtime Error 3134 - Syntax Error in INSERT INTO Statement

    Hello all,
    First time poster here. I have worked with VB6 in the past but am a little rusty. My employer gave me a database (already partially constructed) to work on in my free time. I am using MS Access 2007. My current issue is with the following code which executes on a button click on an unbound form:

    Code:
    Private Sub Command44_Click()
        Dim query1 As String
        query1 = "INSERT INTO User (Last Name, First Name, User name, Location, " & _
        "Staff ID, Email1, Email2, Nickname, Address, City, State, Zip, Home Phone, " & _
        "Cell Phone, Notes) VALUES ('" & Me!LastName.Value & "', '" & Me!FirstName.Value _
        & "', '" & Me!Username.Value & "', '" & Me!Location.Value & "', '" & Me!StaffID.Value _
        & "', '" & Me!Email1.Value & "', '" & Me!Email2.Value & "', '" & Me!Nickname.Value _
        & "', '" & Me!Address.Value & "', '" & Me!City.Value & "', '" & Me!State.Value _
        & "', " & Me!Zip.Value & ", " & Me!HomePhone.Value & ", " & Me!CellPhone.Value _
        & ", '" & Me!Notes.Value & "');"
        Debug.Print query1
        DoCmd.RunSQL query1
    End Sub
    The results of the Debug.Print statement are:
    Code:
    INSERT INTO User (Last Name, First Name, User name, Location, Staff ID, Email1, Email2, Nickname, Address, City, State, Zip, Home Phone, Cell Phone, Notes) VALUES ('Smith', 'John', 'jsmith', 'MHS', 'JK38471', 'jsmith@blah.com', 'smithj@blargh.edu', 'Jonny', '465 Anywhere St.', 'Anytown', 'AK', 48654, 4564564565, 6548651388, 'Notes about his manů');
    Upon clicking the button I am getting the error in the title:

    Runtime Error 3134 - Syntax Error in INSERT INTO Statement

    I have looked around and have been unable to find an answer to the problem. Any help would be greatly appreciated.

    ~Wiggz

  2. #2
    #28 for the Yanks coming GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,266

    Re: Runtime Error 3134 - Syntax Error in INSERT INTO Statement

    You have spaces in the field names. This is a big no no. Since they are already there enclose each field name with a space in it (ie Last Name) in square bracketes like this [Last Name]
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    12

    Re: Runtime Error 3134 - Syntax Error in INSERT INTO Statement

    *sigh* Thanks, that worked. The guy that worked on this originally set up those names. I didn't like having spaces but it would have required a few changes elsewhere. I went ahead and made those changes and it fixed it. Thanks again.

  4. #4
    #28 for the Yanks coming GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,266

    Re: Runtime Error 3134 - Syntax Error in INSERT INTO Statement

    No problem. Happy to have helped. If this resolves your issue could you do us a favor and use the thread toos and mark this as resolved.

    Thanks
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.