ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   database connection question (https://www.excelbanter.com/excel-programming/433337-database-connection-question.html)

Charles Law

database connection question
 
how to connect to and get data from sql server express 2008 using VBA?

Thanks
Charles

Jacob Skaria

database connection question
 
Refer the below link
http://www.ozgrid.com/forum/showthread.php?t=83016

If this post helps click Yes
---------------
Jacob Skaria


"Charles Law" wrote:

how to connect to and get data from sql server express 2008 using VBA?

Thanks
Charles


Patrick Molloy

database connection question
 
this will get you started. Open the dev environment (ALT+F11) then set a
reference (Tools / References) to the Microsoft Active Data Objects 2.6
Library

paste this into a new sub:
SUB Demo()
Dim rst As ADODB.Recordset
Dim db As Connection
Dim SQL As String
Set db = New Connection

With db
.CursorLocation = adUseClient
.Open "PROVIDER=MSDASQL;driver={SQL
Server};server=Patrick-PC;uid=;pwd=;database=MyDatabase;"
End With

Set rst = New Recordset
SQL = "select * from products"
rst.Open SQL, db, adOpenStatic, adLockOptimistic
range("A1").CopyFromRecordset rst

rst.Close
db.Close
set rst = Nothing
set db = Nothing
End Sub



"Charles Law" wrote in message
...
how to connect to and get data from sql server express 2008 using VBA?

Thanks
Charles




All times are GMT +1. The time now is 01:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com