Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default database connection question

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

Thanks
Charles
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
database connection dsn vs. odc alex Excel Programming 2 June 3rd 08 04:50 PM
Database Connection srikanth Excel Programming 1 February 6th 07 11:39 PM
Database Connection Phil Excel Programming 1 September 30th 05 12:25 PM
Database Connection Jake Marx[_3_] Excel Programming 0 July 1st 05 03:50 PM
DataBase Connection willie[_2_] Excel Programming 0 January 27th 04 10:06 PM


All times are GMT +1. The time now is 10:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"