Function returns RecordSet - TestMe - 06-19-2009
Hi All,
Is it possible to return a RecordSet from a function.
Just like return value from function.
I tried this code :
******************************
Code: Function GetData()
Set objConnection=fgGetConnection
strQuery = "SELECT * FROM [DATA$]"
Set RecordSet = CreateObject("ADODB.recordset")
RecordSet.Open strQuery, objConnection
GetData=RecordSet
End Function
The Function call :
Code: Set RecordSet = CreateObject("ADODB.recordset")
RecordSet = GetData
*****************************
But Im getting an error with Wrong Parameter
Thanks
TestMe
RE: Function returns RecordSet - QTPian - 06-23-2009
Hi,
You can return a record set object by using SET keyword.
In your function, use Set before GetData=RecordSet
Set GetData=RecordSet
Hope this helps!!!
RE: Function returns RecordSet - TestMe - 06-23-2009
Hi,
Actually I tried this one earlier.Sry it'll not work...
RE: Function returns RecordSet - QTPian - 06-24-2009
Hi, I found a solution for the problem. The following code works for me.
*******************
Code: Set conn=createobject("adodb.connection")
Set rec_set=createobject("adodb.recordset")
function getrs()
str_con= "dsn=dsn name"
conn.open str_con, "username", "password"
rec_set.open "select * from table", conn, 2, 3
Set getrs = rec_set
End Function
Set RdSt = getrs
RdSt.movefirst
msgbox(RdSt(0))
rec_set.close
conn.close
Set RdSt = Nothing
*********************
Here I have declared the connection object and recordset object globally (above the function). I have also used Set keyword infront of the function call (Set RdSt=getrs).
Revert back with your thoughts on the above code.
Thanks,
|