I have an excel invoice sheet and I want to write the information from the invoice to a table in an Access file. My following code is:
Private Sub Button66_Click()
Dim con As New ADODB.Connection
Dim connectionString As String
Dim sql As String
connectionString = "DBQ=c:\Users\Public\Public Desktop\InvoiceRecords.mdb; Driver={Microsoft Access Driver (*.mdb)};"
con.Open connectionString
sql = "insert into Invoices (Customer, Address) values(G6, G7)"
con.Execute sql
MsgBox "Values entered", vbInformation
con.Close
Set con = Nothing
End Sub
However, when I run it I get a runtime-error ‘-2147217904 (80040e10)’; Too few parametersentered.
I’m not what sure what this is.
Any ideas or suggestions? Thanks a bunch!
I think the problem is you’re trying to get at the values of cells G6 and G7 in your INSERT query. You need to concatenate them into your insert query instead.
Building your sql commands this way makes you vulnerable to SQL injection. A better alternative is to use a parameterized query.
You should also use the Jet driver to connect, instead of the ODBC driver. Use this connection string instead.