Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Pass an ADO recordset

Hello.

Is is possible to structure VBA code so that I can call a
function that runs a query, say in ADO, return the data to
a recordset and then return that recordset to the calling
subroutine in another module?

If so, I need some example code that illustrates how to do
this. I have been unsuccessful so far. My call to the
function works and the query returns the data into the
recordset, but I can't seem to pass the recordset back to
the calling subroutine. Apparently, you can't pass it like
an array? ...Unless I not dimensioning my variables
correctly???

Your example code would be most helpful. Thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Pass an ADO recordset

Hi

If you set reference to ADO (Microsoft ActiveX Data Objects) then you have a
datatype called ADODB.Recordset that I believe you can pass like this:

Sub test()
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
'Open db, Get data, ...
Call Another(Rst)
Cnn.Close
Set Rst = Nothing
Set Cnn = Nothing
End Sub

Sub Another(Rst As ADODB.Recordset)
'do stuff
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Quartz" skrev i melding
...
Hello.

Is is possible to structure VBA code so that I can call a
function that runs a query, say in ADO, return the data to
a recordset and then return that recordset to the calling
subroutine in another module?

If so, I need some example code that illustrates how to do
this. I have been unsuccessful so far. My call to the
function works and the query returns the data into the
recordset, but I can't seem to pass the recordset back to
the calling subroutine. Apparently, you can't pass it like
an array? ...Unless I not dimensioning my variables
correctly???

Your example code would be most helpful. Thanks in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Pass an ADO recordset

Thanks Harald! My preferred structure would be more like
the following - is something like this possible?:

Sub Main_Sub()

....other code...

'Call query function and return recordset
rst = RunADOQueryFunction(strFullName, strSQL, strTable)

....do stuff with rst...

rst.close

end sub

-----Original Message-----
Hi

If you set reference to ADO (Microsoft ActiveX Data

Objects) then you have a
datatype called ADODB.Recordset that I believe you can

pass like this:

Sub test()
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
'Open db, Get data, ...
Call Another(Rst)
Cnn.Close
Set Rst = Nothing
Set Cnn = Nothing
End Sub

Sub Another(Rst As ADODB.Recordset)
'do stuff
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Quartz" skrev i

melding
...
Hello.

Is is possible to structure VBA code so that I can call

a
function that runs a query, say in ADO, return the data

to
a recordset and then return that recordset to the

calling
subroutine in another module?

If so, I need some example code that illustrates how to

do
this. I have been unsuccessful so far. My call to the
function works and the query returns the data into the
recordset, but I can't seem to pass the recordset back

to
the calling subroutine. Apparently, you can't pass it

like
an array? ...Unless I not dimensioning my variables
correctly???

Your example code would be most helpful. Thanks in

advance.



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Pass an ADO recordset

Probably. Datatypes are datatypes. Try making something like

Function RunADOQuery(whatever as whatever) As ADODB.Recordset
Dim Cnn As New ADODB.Connection
'...

and

Sub Main_Sub()
Dim Rst As ADODB.Recordset
'...
Set Rst = RunADOQueryFunction(variables...)

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Quartz" skrev i melding
...
Thanks Harald! My preferred structure would be more like
the following - is something like this possible?:

Sub Main_Sub()

...other code...

'Call query function and return recordset
rst = RunADOQueryFunction(strFullName, strSQL, strTable)

...do stuff with rst...

rst.close

end sub

-----Original Message-----
Hi

If you set reference to ADO (Microsoft ActiveX Data

Objects) then you have a
datatype called ADODB.Recordset that I believe you can

pass like this:

Sub test()
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
'Open db, Get data, ...
Call Another(Rst)
Cnn.Close
Set Rst = Nothing
Set Cnn = Nothing
End Sub

Sub Another(Rst As ADODB.Recordset)
'do stuff
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Quartz" skrev i

melding
...
Hello.

Is is possible to structure VBA code so that I can call

a
function that runs a query, say in ADO, return the data

to
a recordset and then return that recordset to the

calling
subroutine in another module?

If so, I need some example code that illustrates how to

do
this. I have been unsuccessful so far. My call to the
function works and the query returns the data into the
recordset, but I can't seem to pass the recordset back

to
the calling subroutine. Apparently, you can't pass it

like
an array? ...Unless I not dimensioning my variables
correctly???

Your example code would be most helpful. Thanks in

advance.



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Pass an ADO recordset

Using Harald;s example, could you not just use

Function RunADOQueryFunction(strFullName, strSQL, strTable)
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
'Open db, Get data, ...
RunADOQueryFunction =Rst
Cnn.Close
Set Rst = Nothing
Set Cnn = Nothing
End Sub

Sub Main()

rst = RunADOQueryFunction(strFullName, strSQL, strTable)

End Sub

This assumes you know how to connect and issue the SQL and get the recordset
back. Or is that the real question ?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Quartz" wrote in message
...
Thanks Harald! My preferred structure would be more like
the following - is something like this possible?:

Sub Main_Sub()

...other code...

'Call query function and return recordset
rst = RunADOQueryFunction(strFullName, strSQL, strTable)

...do stuff with rst...

rst.close

end sub

-----Original Message-----
Hi

If you set reference to ADO (Microsoft ActiveX Data

Objects) then you have a
datatype called ADODB.Recordset that I believe you can

pass like this:

Sub test()
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
'Open db, Get data, ...
Call Another(Rst)
Cnn.Close
Set Rst = Nothing
Set Cnn = Nothing
End Sub

Sub Another(Rst As ADODB.Recordset)
'do stuff
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Quartz" skrev i

melding
...
Hello.

Is is possible to structure VBA code so that I can call

a
function that runs a query, say in ADO, return the data

to
a recordset and then return that recordset to the

calling
subroutine in another module?

If so, I need some example code that illustrates how to

do
this. I have been unsuccessful so far. My call to the
function works and the query returns the data into the
recordset, but I can't seem to pass the recordset back

to
the calling subroutine. Apparently, you can't pass it

like
an array? ...Unless I not dimensioning my variables
correctly???

Your example code would be most helpful. Thanks in

advance.



.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Pass an ADO recordset


Thanks Harald (and all who responded), I was missing
the "As ADODB.Recordset" outside the parentheses.

Function RunADOQuery(args) As ADODB.Recordset


-----Original Message-----
Probably. Datatypes are datatypes. Try making something

like

Function RunADOQuery(whatever as whatever) As

ADODB.Recordset
Dim Cnn As New ADODB.Connection
'...

and

Sub Main_Sub()
Dim Rst As ADODB.Recordset
'...
Set Rst = RunADOQueryFunction(variables...)

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Quartz" skrev i

melding
...
Thanks Harald! My preferred structure would be more like
the following - is something like this possible?:

Sub Main_Sub()

...other code...

'Call query function and return recordset
rst = RunADOQueryFunction(strFullName, strSQL, strTable)

...do stuff with rst...

rst.close

end sub

-----Original Message-----
Hi

If you set reference to ADO (Microsoft ActiveX Data

Objects) then you have a
datatype called ADODB.Recordset that I believe you can

pass like this:

Sub test()
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
'Open db, Get data, ...
Call Another(Rst)
Cnn.Close
Set Rst = Nothing
Set Cnn = Nothing
End Sub

Sub Another(Rst As ADODB.Recordset)
'do stuff
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Quartz" skrev i

melding
...
Hello.

Is is possible to structure VBA code so that I can

call
a
function that runs a query, say in ADO, return the

data
to
a recordset and then return that recordset to the

calling
subroutine in another module?

If so, I need some example code that illustrates how

to
do
this. I have been unsuccessful so far. My call to the
function works and the query returns the data into

the
recordset, but I can't seem to pass the recordset

back
to
the calling subroutine. Apparently, you can't pass it

like
an array? ...Unless I not dimensioning my variables
correctly???

Your example code would be most helpful. Thanks in

advance.



.



.

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
query a recordset SAm Excel Discussion (Misc queries) 2 May 1st 07 09:33 PM
return recordset Laurent M Excel Discussion (Misc queries) 4 January 26th 05 09:43 AM
Recordset Stephan Kassanke Excel Programming 0 September 10th 03 04:45 PM
Looping Through A Recordset Tim Williams Excel Programming 0 August 20th 03 05:52 AM
Looping Through A Recordset Bob Phillips[_5_] Excel Programming 0 August 19th 03 03:34 PM


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