Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function returns RecordSet
#1
Solved: 11 Years, 3 Months, 4 Weeks ago Exclamation 
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
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
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!!!
Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi,
Actually I tried this one earlier.Sry it'll not work...Sad
Reply
#4
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi, I found a solution for the problem.Cool 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,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  GetRows() not fetching the exact record from the recordset Saranyaciet2 0 2,776 05-27-2015, 11:15 AM
Last Post: Saranyaciet2
  Calling a Function in Function Library when function is defined in an Action jitenderkkr 0 2,973 11-27-2014, 12:53 PM
Last Post: jitenderkkr
  Webtable().GetCellData() Returns hidden values of Cells ssvali 4 5,977 06-07-2013, 08:37 PM
Last Post: kawsar
  QTP - Webtable().GetCellData() returns unknown symbols and spaces lokesh8008 2 4,831 05-10-2013, 03:49 AM
Last Post: sria123
  Creating an array from an specific field in the recordset Arena 0 2,477 04-04-2012, 09:58 PM
Last Post: Arena

Forum Jump:


Users browsing this thread: 3 Guest(s)