Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
See if this helps. Don't forget to; Tools|References and check the box for
'Microsoft ActiveX Data Objects 2.x Library' Use the highest version that will still support your clients. Public Sub testread() Dim cnn As ADODB.Connection Dim rs1 As ADODB.Recordset Dim strSQL1 As String, strConn Dim i As Integer i = 1 'Use for Access (jet) 'strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source=C:\Program Files\Microsoft Office\" _ & "OFFICE11\SAMPLES\Northwind.mdb;Persist Security Info=False" 'Use for SQL server (OLEDB) strConn = "Provider=SQLOLEDB.1;" _ & "Integrated Security=SSPI;" _ & "Persist Security Info=False;" _ & "Initial Catalog=Northwind;" _ & "Data Source=PE1600" strSQL1 = "SELECT LastName, FirstName " _ & "FROM Employees; " Set cnn = New ADODB.Connection Set rs1 = New ADODB.Recordset cnn.Open strConn rs1.Open strSQL1, cnn, adOpenForwardOnly, adLockReadOnly Do While rs1.EOF = False Sheets("Sheet1").Range("A" & i) = rs1!LastName Sheets("Sheet1").Range("B" & i) = rs1!FirstName i = i + 1 rs1.MoveNext Loop rs1.Close cnn.Close End Sub Public Sub testwrite() Dim cnn As ADODB.Connection Dim rs1 As ADODB.Recordset Dim strSQL1 As String, strConn Dim i As Integer i = 1 'Use for Access (jet) 'strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source=C:\Program Files\Microsoft Office\" _ & "OFFICE11\SAMPLES\Northwind.mdb;Persist Security Info=False" 'Use for SQL server (OLEDB) strConn = "Provider=SQLOLEDB.1;" _ & "Integrated Security=SSPI;" _ & "Persist Security Info=False;" _ & "Initial Catalog=Northwind;" _ & "Data Source=PE1600" strSQL1 = "SELECT LastName, FirstName " _ & "FROM Employees; " Set cnn = New ADODB.Connection Set rs1 = New ADODB.Recordset cnn.Open strConn rs1.Open strSQL1, cnn, adOpenDynamic, adLockOptimistic For i = 1 To 3 rs1.AddNew rs1!LastName = Sheets("Sheet1").Range("A" & i) rs1!FirstName = Sheets("Sheet1").Range("B" & i) i = i + 1 rs1.Update Next rs1.Close cnn.Close End Sub -- Regards, Dave Patrick ....Please no email replies - reply in newsgroup. Microsoft Certified Professional Microsoft MVP [Windows] http://www.microsoft.com/protect "Dave" wrote: I have an Excel Spreadsheet that is populated from a SQL Database. There are several fields to be updated on a daily basis. I am looking for help on the code necessary to write the changes back to the SQL database. I used some ADODB connections strings in other script, but cannot figure out in Excel VBA. Thanks |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Stop Excel's UPDATE\Don't UPDATE message box from appearing every time I open the work book | Excel Programming | |||
Data Validation lists update orginal cell with list update | Excel Worksheet Functions | |||
i want to update one excel file the other one update automaticaly | New Users to Excel | |||
Telling excel to update or not to update | Excel Programming | |||
Excel 2003 - Update or Don't Update Links Problem | Excel Programming |