Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Still trying to figure this one out. I am connecting to Access in a
user-defined function and trying to run two separate queries off the same connection. What is curious is that if I create it as a Sub and run the macro, using CopyFromRecordset to dump the final results of my two queries into a worksheet, this code runs fine. But if I do it as a Function, then it does not work and exits the function when I get to the second recordset open (rst2.Open) command. Below is the basic structure of my code. Any ideas? Function DataFetch (input parameters here) Dim conn As New ADODB.Connection Dim rst1 As New ADODB.Recordset Dim rst2 As New ADODB.Recordset Dim SQLstr1 As String Dim SQLstr2 As String Dim ProjNum As String SQLstr1 = "SELECT blah blah ..." conn.Open "Provider=Microsoft.Jet.OLEDB.*4.0;" & _ "Data Source=G:\DB\CMdb.mdb;" rst1.Open SQLstr1, conn If rst1 = condition Then (change the value of one of the input parameters) rst1.Close SQLstr2 = "SELECT blah blah ..." (this query will return one and only one value) rst2.Open SQLstr2, conn DataFetch = rst2.Fields(0).Value rst2.Close conn.Close End Function |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to: User Form to assign a user defined range to a macro variab | Excel Programming | |||
Macro user defined function row information | Excel Programming | |||
User Defined Function used in Macro returns #VALUE | Excel Programming | |||
User-defined data type; Error: Only User-defined types... | Excel Programming | |||
User-Defined Function pre-empting Built-in Function? How to undo???? | Excel Programming |