Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Calling Microsoft Excel ODBC Query

Hi all,
I have an Excel query that extracts data from my Microsoft
Access database. Is there anyone be kind enough to show me
how to call the query in Excel using VBA? I can double
click it in Window Explorer to get the data but I don't
know how to do it in Excel VBA.

Appreciate your help!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Calling Microsoft Excel ODBC Query

Install the MS ADO library, this is in the VBE, Tools, References:
Microsoft ActiveX Data Objects 2.x Library

Then this is a simple example of code:

Sub test()

Dim rs As ADODB.Recordset
Dim strConnect As String
Dim strSQL As String

strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Test.mdb;"

strSQL = "SELECT I.SURNAME FROM IdTable I WHERE I.ID = 7800"

Set rs = New ADODB.Recordset

rs.Open strSQL, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

MsgBox rs.Fields(0)

rs.Close
Set rs = Nothing

End Sub


RBS


"Steve C." wrote in message
...
Hi all,
I have an Excel query that extracts data from my Microsoft
Access database. Is there anyone be kind enough to show me
how to call the query in Excel using VBA? I can double
click it in Window Explorer to get the data but I don't
know how to do it in Excel VBA.

Appreciate your help!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Calling Microsoft Excel ODBC Query

Thanks RBS. Have a nice day!
-----Original Message-----
Install the MS ADO library, this is in the VBE, Tools,

References:
Microsoft ActiveX Data Objects 2.x Library

Then this is a simple example of code:

Sub test()

Dim rs As ADODB.Recordset
Dim strConnect As String
Dim strSQL As String

strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Test.mdb;"

strSQL = "SELECT I.SURNAME FROM IdTable I WHERE I.ID

= 7800"

Set rs = New ADODB.Recordset

rs.Open strSQL, strConnect, adOpenForwardOnly,

adLockReadOnly, adCmdText

MsgBox rs.Fields(0)

rs.Close
Set rs = Nothing

End Sub


RBS


"Steve C." wrote in

message
...
Hi all,
I have an Excel query that extracts data from my

Microsoft
Access database. Is there anyone be kind enough to show

me
how to call the query in Excel using VBA? I can double
click it in Window Explorer to get the data but I don't
know how to do it in Excel VBA.

Appreciate your help!



.

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
Microsoft Query/ODBC issue Jombe Excel Discussion (Misc queries) 0 September 7th 07 09:08 PM
Syntax Error - Using Microsoft Query and ODBC link to a table James T Excel Discussion (Misc queries) 0 August 31st 05 02:18 AM
Excel ODBC Query H. Zhu Excel Programming 1 December 12th 03 03:42 AM
EXCEL AND ODBC AND QUERY Gary B[_3_] Excel Programming 1 August 5th 03 02:39 AM
How to insert data into microsoft excel sheet using ODBC API Siddharth Mehta Excel Programming 0 July 31st 03 06:57 AM


All times are GMT +1. The time now is 09:56 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"