How to connect to SQL db & update cells

  • Thread starter Thread starter ChrisB
  • Start date Start date
C

ChrisB

Does someone have some sample code, or maybe point me to a
resource?

I have an excel spreadsheet, Column A has EmployeeID#'s,
say 500 rows worth. I want to loop thru each EmployeeID in
ColA and query a SQL Server database for LastName,
FirstName, etc. to populate ColB, ColC, etc.

Any help would be extremely appreciated.

Thanks in advance,
ChrisB
 
My Guess is that your used ADODB or DAO - I've not used them to connect to a SQL Server database but have done so with Access Databases - the code below adds some records to an access db - I think you would need to change the provider - do you have a connection string for the SQL db

Sub DelFirstRec(
Dim rst As ADODB.Recordse
Set rst = New ADODB.Recordse
rst.Open "table name or SQL statement", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\___\db1.mdb;",
adOpenKeyset, adLockOptimisti
With rs
.AddNe
![1] = "1
![2] = "2
.Updat
.Clos
End Wit

End Sub
 
Back
Top