Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Syntax Error in Insert Statement (VB6)

    I am assuming it is where I am concatenating the FullName value, but I'm not sure. Can anyone see where I'm going wrong?

    gsConn.Execute ("INSERT INTO tblEmpl " _
    & "(LastName, FirstName, FullName, Ext, Email, Epager) " _
    & "VALUES ('" & txtLastName.Text & "', " _
    & "'" & txtFirstName.Text & "', " _
    & "'" & txtLastName & ", " & txtFirstName.Text & "', " _
    & "'" & txtExt.Text & "', " _
    & "'" & txtEmail.Text & "', " _
    & "'" & txtEPager.Text & "'")

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Syntax Error in Insert Statement (VB6)

    Here's your problem:

    & "'" & txtLastName & ", " & txtFirstName.Text & "', " _

    You left off the Text property reference for txtLastName.
    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax Error in Insert Statement (VB6)

    I tried several variations, in fact I'm quite sure I've tried them all except for the one that is supposed to work. Did you understand that this is a concatenation of two text boxes that is going into one field (FullName ) in the database? Since it is last name first I need to represent the comma in the text string. For some reason I'm getting really tripped up by this.

  4. #4
    Star Lounger
    Join Date
    Jan 2001
    Location
    L.A., California
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax Error in Insert Statement (VB6)

    I don't think you actually NEED to include the .Text, as that's the default property of a text box. I think your real problem is that your sql statement "thinks" the second occurrences of last name & first name are 2 distinct fields, and therefore the values you supplied don't match the field name list you specified. Try this:
    <pre>Dim sSql As String

    sSql = "Insert Into tblEmpl (LastName, " _
    & "FirstName, FullName, Ext, " _
    & "Email, Epager) Values ('" _
    & txtLastName.Text & "', '" & txtFirstName.Text & "', '" _
    & txtLastName.Text & "", "" & txtFirstName.Text & "', '" _
    & txtExt.Text & "', '" & txtEmail.Text & "', '" _
    & txtEPager.Text & "')"

    gsConn.Execute (sSql)

    </pre>


    Note the 2 double quotes between last & first names. When building a string, they create a double quote in the string. Try putting a break point immediately after the first statement, then printing sSql in the immediate window to see the results.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax Error in Insert Statement (VB6)

    This returned an error that it was expecting an end of statement. When I put my code through the debug window the syntax seemed to be correct.

    And you're right, you don't need the .Text property in the reference. It is something I've just decided for myself that it is a good habbit.

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax Error in Insert Statement (VB6)

    AH, I just figured it out. I didn't end the Execute statement correctly by not closing with a quote and parenthesis:

    gsConn.Execute ("INSERT INTO tblEmpl " _
    & "(LastName, FirstName, FullName, Ext, Email, Epager) " _
    & "VALUES ('" & txtLastName.Text & "', " _
    & "'" & txtFirstName.Text & "', " _
    & "'" & txtLastName & ", " & txtFirstName.Text & "', " _
    & "'" & txtExt.Text & "', " _
    & "'" & txtEmail.Text & "', " _
    & "'" & txtEPager.Text & "')")

    Sorry to put everyone through this, and thanks for your help.

  7. #7
    Star Lounger
    Join Date
    Jan 2001
    Location
    L.A., California
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Syntax Error in Insert Statement (VB6)

    On the statement which sets the sSql variable, make sure that on every line except the last one there is a space and an underscore at the end of the line. The space is very important. I use code like this all the time, and it usually works fine. The advantage of this is it's cleaner looking code, and you can test the value of the sql statement before trying to execute it. BTW, I agree on the ".Text" issue. With .net, I hear default properties are not allowed, so good habits now.....

Posting Permissions

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