LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default ADO connection/SQL query in Excel function

I'm new to this, so be kind and answer in plain English please. :)

I have written a user-defined function that connects to an Access db
and performs a query, returning a value to a cell in Excel. It works
great. But I have discovered that I need to do an initial query first
and, depending on its results, have my function perform one of several
possible second queries.

My problem is I don't quite understand the mechanics of how the
connection to the db works. The code I am using, after building my
query and assigning it to the string variable SQLstr is:

conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=G:\DB\CMdb.mdb;"
rst.Open SQLstr, conn
DataFetch = rst.Fields(0).Value

(DataFetch is the function's name, and the query always returns one and
only one value)

What do I need to do if I want to establish the connection, build a
SQLstr and perform a query with it, then build a second SQLstr and
perform a second query with it (the results of which will become the
function's ret val, as above)? Do I need to re-establish a connection
for each query, or will a connection early on in the function stay open
until the end? I hope I am being specific enough here. Thanks.

 
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
Network connection for query ken Excel Discussion (Misc queries) 0 February 12th 10 07:43 AM
Connection of Excel 07 pivot table to Access Query makes DB read o Chuck W[_2_] Excel Discussion (Misc queries) 0 October 9th 09 03:45 PM
Change Connection of a Query Jean-Francois Excel Discussion (Misc queries) 1 October 6th 05 12:16 AM
use variable as connection in query table? Kieran1028[_4_] Excel Programming 0 November 8th 04 08:19 PM
MS Query - DB connection Dean[_4_] Excel Programming 0 November 26th 03 07:43 PM


All times are GMT +1. The time now is 05:51 PM.

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

About Us

"It's about Microsoft Excel"