T
todtown
I'm trying to do this in VBA:
Dim cn As New ADODB.Connection
Dim sql As String
cn.Open "Driver={SQL
Server};Server=servername;Database=dbname;Uid=userid;Pwd=password"
sql = "INSERT INTO table_name " & _
"(field_1,field_2,field_3,field_4) " & _
"Values ('value1','value2','value3','value4')"
cn.Execute sql
I get an automation error with the Execute method. However, if I run
the query from Query Analyzer it works. So, I'm pretty sure the
problem is either I'm not setting up the sql string properly to use
with cn.Execute, or I'm using the wrong ADO objects/methods.
How do I do this correctly?
tod
Dim cn As New ADODB.Connection
Dim sql As String
cn.Open "Driver={SQL
Server};Server=servername;Database=dbname;Uid=userid;Pwd=password"
sql = "INSERT INTO table_name " & _
"(field_1,field_2,field_3,field_4) " & _
"Values ('value1','value2','value3','value4')"
cn.Execute sql
I get an automation error with the Execute method. However, if I run
the query from Query Analyzer it works. So, I'm pretty sure the
problem is either I'm not setting up the sql string properly to use
with cn.Execute, or I'm using the wrong ADO objects/methods.
How do I do this correctly?
tod