Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I've been able to execute select statements to retrieve
selective data from SQL Server inside of the VBA code in Excel. What commands are necessary to Insert records into the same database and table? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
John
If you are using ADO, here's an example of how to add a record. You'll need to set a reference to the ActiveX Data Objects Library under Tools - References. Sub AddRec() Dim mycn As ADODB.Connection Dim i As Integer Dim mySQL As String Dim stConn As String Dim myRS As ADODB.Recordset mySQL = "SELECT `Table 1`.number, `Table 1`.name, `Table 1`.TheDate" mySQL = mySQL & " FROM `c:\Dick\db1`.`Table 1` `Table 1`" stConn = "DSN=MS Access 97 Database;DBQ=c:\Dick\db1.mdb;" stConn = stConn & "DefaultDir=c:\Dick;DriverId=281;" stConn = stConn & "FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;" Set mycn = New ADODB.Connection mycn.Open stConn Set myRS = New ADODB.Recordset myRS.Open mySQL, mycn, adOpenDynamic, adLockOptimistic With myRS .AddNew .Fields(0).Value = 40 .Fields(1).Value = "Name" .Fields(2).Value = Now .Update End With myRS.Close mycn.Close End Sub -- Dick Kusleika MVP - Excel www.dicks-clicks.com Post all replies to the newsgroup. "John" wrote in message ... I've been able to execute select statements to retrieve selective data from SQL Server inside of the VBA code in Excel. What commands are necessary to Insert records into the same database and table? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks. I've been using ODBC but am going to give this a
try. -----Original Message----- John If you are using ADO, here's an example of how to add a record. You'll need to set a reference to the ActiveX Data Objects Library under Tools - References. Sub AddRec() Dim mycn As ADODB.Connection Dim i As Integer Dim mySQL As String Dim stConn As String Dim myRS As ADODB.Recordset mySQL = "SELECT `Table 1`.number, `Table 1`.name, `Table 1`.TheDate" mySQL = mySQL & " FROM `c:\Dick\db1`.`Table 1` `Table 1`" stConn = "DSN=MS Access 97 Database;DBQ=c:\Dick\db1.mdb;" stConn = stConn & "DefaultDir=c:\Dick;DriverId=281;" stConn = stConn & "FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;" Set mycn = New ADODB.Connection mycn.Open stConn Set myRS = New ADODB.Recordset myRS.Open mySQL, mycn, adOpenDynamic, adLockOptimistic With myRS .AddNew .Fields(0).Value = 40 .Fields(1).Value = "Name" .Fields(2).Value = Now .Update End With myRS.Close mycn.Close End Sub -- Dick Kusleika MVP - Excel www.dicks-clicks.com Post all replies to the newsgroup. "John" wrote in message ... I've been able to execute select statements to retrieve selective data from SQL Server inside of the VBA code in Excel. What commands are necessary to Insert records into the same database and table? . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
insert records? | Excel Worksheet Functions | |||
insert records | Excel Worksheet Functions | |||
SQL Server -- Bulk Insert from Excel to SQL Server | Excel Discussion (Misc queries) | |||
Insert Next? Or insert a variable number of records...how? | Excel Discussion (Misc queries) | |||
Excel 2003 Error Cannot Locate the Internet Server or Proxy Server | Excel Discussion (Misc queries) |