Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello
It's been a while since I've been programming in classical VB... (no VB.net) I now have to write some Excel VBA stuff to access a Database (SQL-Server) and I don't know how. Is there any good tutorial or can anybody help me? Finally, the user must be able to enter a number in the excel sheet and the macro then gets a record from the database, using the user's input as WHERE-argument Thanks for your help! Simon |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Simon,
Here's a simple example of using ADO to access a SQL Server database. You would need to set all of the connection properties as appropriate, ,and set the SQL command. You will also need to set a reference to Microsoft ActiveX Data Objects n.n Library under Tools/References Dim oConn As ADODB.Connection Dim oRS As ADODB.Recordset Dim iField As Long Set oConn = New ADODB.Connection oConn .CursorLocation = adUseClient oConn .Open "PROVIDER=MSDASQL;driver={SQL Server};" & _ "server=MyServerName;" & _ "uid=MyUID;" & _ "pwd=MyPassword;" & _ "database=MyDatabaseName;" Set oRS = New ADODB.Recordset oRS.Open "SELECT * FROM [MyTable] WHERE fieldx = " & myVar, _ oConn, adOpenStatic,adLockOptimistic ActiveSheet.Cells.Clear If Not oRS.EOF Then For iField = 1 To oRS.Fields.Count Cells(1, iField).Value = oRS.Fields(iField -1).Name Next Range("A2").CopyFromRecordset oRS End If oRS.Close Set oRS= Nothing oConn.Close Set oConn = Nothing -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Simon Sunke" wrote in message ... Hello It's been a while since I've been programming in classical VB... (no VB.net) I now have to write some Excel VBA stuff to access a Database (SQL-Server) and I don't know how. Is there any good tutorial or can anybody help me? Finally, the user must be able to enter a number in the excel sheet and the macro then gets a record from the database, using the user's input as WHERE-argument Thanks for your help! Simon |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Simon,
It's been a while since I've been programming in classical VB... (no VB.net) I now have to write some Excel VBA stuff to access a Database (SQL-Server) and I don't know how. Is there any good tutorial or can anybody help me? Finally, the user must be able to enter a number in the excel sheet and the macro then gets a record from the database, using the user's input as WHERE-argument Check out this site: http://www.erlandsendata.no/english/...odao/index.htm Regards, Jan Karel Pieterse Excel MVP www.jkp-ads.com |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks a lot, works great!
Simon |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Update Excel Database via Access Main Database with a script | New Users to Excel | |||
Access Database | Excel Discussion (Misc queries) | |||
Microsoft Access database | Excel Discussion (Misc queries) | |||
Open Access Database with VBA | Excel Discussion (Misc queries) | |||
Open Access Database with VBA | Excel Discussion (Misc queries) |