Hi I am trying to write a macro that takes the user input from an excel form and adds it to a access table. Using the following code:
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim wsh As Excel.Application
Set cnn = "db.accdb.connection"
Set rst = New ADODB.Recordset
rst.Open "table", cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
With rst
.AddNew
.Fields("column1").Value = textboxvar
.Update
End With
with textboxvar previously defined. But it wont work and I don't know why.
Set cnn = "db.accdb.connection"makes no sense. Do you have valid code there and are you trying to hide private information (like the location and password of your accdb file), or are you actually trying to go with that?Set cnn = "db.accdb.connection"basically means nothing in this scenario. You most likely want to change that like toSet cnn = CreateObject("ADODB.Connection"). For future reference, the.Openmethod requires the second input to be a variable command object.