![]() |
Using ADO with INSERT query
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=user id;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 |
All times are GMT +1. The time now is 08:18 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com