Trying to add record to MS Access DB

lorena

Well-known member
Joined
Oct 23, 2003
Messages
134
Location
Phoenix, Arizona
I keep getting this error:
"Number of query values and destination fields are not the same"
I have exactly the same number of fields in my query that are in the database and they are in the same order. I even went so far as to take the parameter values out and substitute hard-coded values and it still throws up. I am not sure what I am doing wrong. Do I have to have a Primary Key for this to work? All this app does is record form data to be exported to a spreadsheet.
Here is my code:
Sub AddRecord()
Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\intranet\databases\results.mdb"
Dim strSQL, strPlant, strTire, strFilter, strWiper As String
Dim objCommand As OleDb.OleDbCommand
Dim objConn As New OleDb.OleDbConnection(strConnString)
Create SQL String
strSQL = "Insert into PML(Customer, PhoneNo, PlantNo, CarYear, CarMake, CarModel, "
strSQL = strSQL + " DropOff, NeededBy, AirFilter, WiperBlades, Rotation) VALUES "
strSQL = strSQL + " (Ethel Mertz, 555-5555, 1, Toyota, Corolla, 2001, "
strSQL = strSQL + " 730. 430, Y, N, Y)"
objCommand = New OleDb.OleDbCommand(strSQL, objConn)
objConn.Open()
objCommand.ExecuteNonQuery()
objConn.Close()
End Sub
Any help would be appreciated. Thanks
 
You can also try putting a break in after you build strSQL and determine exactly what strSQL states. Then copy and paste that into a query in MS Access and then try to execute it. MS Access usually gives better info about the error when you do it that way.
 
Back
Top