ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Type recordset/recordset? (https://www.excelbanter.com/excel-programming/299070-type-recordset-recordset.html)

FlaviusFlav[_9_]

Type recordset/recordset?
 
Im trying to pass a recordset to a procedure to better separate my cod
but getting a type mismatch.

...
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.open "someurl"
...
(the above all works fine)

dosomething(rs) <---Type mismatch here



private sub dosometing(rs as ADODB.recordset)

end sub

I have a watch on rs, and at the point of the procedure call, it i
listed as Type "recordset/recordset"
What does this mean, and how would I pass this to a procedure

--
Message posted from http://www.ExcelForum.com


Dick Kusleika[_3_]

Type recordset/recordset?
 
Flav

It works okay for me.

Sub bbb(rs As ADODB.Recordset)

Debug.Print TypeName(rs)
Debug.Print rs.Fields(1).Value

End Sub

returns Recordset and the proper field value. To which version of ADO have
you set a reference?

You could type your argument As Object which might take care of it, but I'd
be interested to know what's going on. I used XL2000, Win98, ADO 2.7 and
also tested ADO 2.1.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"FlaviusFlav " wrote in message
...
Im trying to pass a recordset to a procedure to better separate my code
but getting a type mismatch.

..
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.open "someurl"
..
(the above all works fine)

dosomething(rs) <---Type mismatch here



private sub dosometing(rs as ADODB.recordset)

end sub

I have a watch on rs, and at the point of the procedure call, it is
listed as Type "recordset/recordset"
What does this mean, and how would I pass this to a procedure?


---
Message posted from http://www.ExcelForum.com/




Bob Phillips[_6_]

Type recordset/recordset?
 
Flavius,

By using

dosomething(rs)

the rs is being evaluated before passed to the procedure. Use

dosomething rs

--

HTH

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

"FlaviusFlav " wrote in message
...
Im trying to pass a recordset to a procedure to better separate my code
but getting a type mismatch.

..
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.open "someurl"
..
(the above all works fine)

dosomething(rs) <---Type mismatch here



private sub dosometing(rs as ADODB.recordset)

end sub

I have a watch on rs, and at the point of the procedure call, it is
listed as Type "recordset/recordset"
What does this mean, and how would I pass this to a procedure?


---
Message posted from http://www.ExcelForum.com/




FlaviusFlav[_10_]

Type recordset/recordset?
 
Thanks for the help Bob.

I'm so used to using parens around arguments that I didnt think t
think that its just evaluating the containing expressio

--
Message posted from http://www.ExcelForum.com


onedaywhen

Type recordset/recordset?
 
FlaviusFlav wrote ...

rs.open "someurl"
dosomething(rs) <---Type mismatch here
private sub dosometing(rs as ADODB.recordset)


What puzzle's me is why you would want to pass an *open* recordset by
reference to a procedure. It would be very complicated for the calling
procedure if the dosometing code changed the rs pointer to reference
another recordset object. I suspect you want

Private Sub DoSometing(ByVal rs as ADODB.Recordset)

It pays to always be explicit; don't rely on default behavior. Ask
yourself whether you want ByVal or ByRef: the answer is usually ByVal
but the default is ByRef. Being explicit will help the person who
inherits your project when you move on to greater things.

--


All times are GMT +1. The time now is 04:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com