Syntax error on 'INSERT INTO' statement when trying to add to access database

Sorry if this should be in the DB area, but not sure if the problem is the DB or the VB code.  

The following code does not work (I get a syntax error in INSERT INTO message).  The database QSSupport.mdb is in the correct path with a table called 'tblKey'.  That table has only one field called 'KeyCode2'.  That field is a text field (50 characters), is not indexed, duplicates and zero length strings are allowed.  Can anyone tell me why this is not working?:

Public Sub Update
        Dim conDB2 As New OleDb.OleDbConnection
        Dim cmdKey As New OleDb.OleDbCommand
        Dim myDS As New DataSet

        conDB2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\QSSupport.mdb"

        cmdKey.CommandText = "INSERT INTO tblKey [keycode2] VALUES '7'"
        cmdKey.Connection = conDB2
        conDB2.Open()
        cmdKey.ExecuteNonQuery()
End Sub
rbertkeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
MikeMCSDConnect With a Mentor Commented:
forget that last post, I was wrong.

Try this:

"INSERT INTO tblKey [keycode2] VALUES '7'"

Change to:

"INSERT INTO tblKey (keycode2) VALUES ('7')"

I added (  ) in 2 places


0
 
MikeMCSDCommented:

Change:   conDB2.Open()

       To:   cmdKey.Open()


0
 
rbertkeAuthor Commented:
I had tried variations so much that I thought this had been tried...Obviously not as this worked...Thanks very much!  Rob
0
All Courses

From novice to tech pro — start learning today.