How to return a recordset from a function and process it accordingly.
the statement "RecSet.Open ", script execution stops abruptly.
Sub sub_CallFunction
' -------------------------------------------------------------------------------------
Dim RecSet, varServiceAgentCount ' Database Integration
MsgBox(aqObject.GetVarType(RecSet)) ' Returns 0, i.e. "vbEmpty" Type
Set RecSet = CreateObject("ADODB.Recordset")
Set RecSet = fn_ExecuteQuery("select count(*) from user_information ui "_
& " where ui.is_clientmanager_user='Y' and ui.account_dead='N'")
MsgBox(aqObject.GetVarType(RecSet)) ' Returns 9, i.e. "vbObject" Type
Set colMethods = aqObject.GetMethods(RecSet)
While colMethods.HasNext
Log.Message(colMethods.Next.Name)
WEnd
' Returns following methods:
' AddNew, CancelUpdate, Close, Delete, GetRows, Move, MoveNext, MovePrevious, MoveFirst, MoveLast, Open, Requery, Update,
' UpdateBatch, CancelBatch, NextRecordset, Supports, Find, Cancel, GetString, CompareBookmarks, Clone, Resync,Seek, Save
Set colProperties = aqObject.GetProperties(RecSet)
While colProperties.HasNext
Log.Message(colProperties.Next.Name)
WEnd
' Returns following properties:
' Properties, AbsolutePosition, ActiveConnection, BOF, Bookmark,CacheSize, CursorType, EOF, Fields, LockType, MaxRecords,
' RecordCount, Source, ' AbsolutePage, EditMode, Filter, PageCount, PageSize, Sort, Status, State, CursorLocation,
' MarshalOptions, DataSource, ActiveCommand, StayInSync, DataMember, Index
RecSet.Open ' Script execution stops: ADODB.Recordset.
' The connection cannot be used to perform this operation. It is either closed or invalid in this context
RecSet.MoveFirst
while Not RecSet.EOF
Call Log.Message(RecSet.Fields(0).Value)
Call RecSet.MoveNext
wend
Next
End Sub
Function fn_CalledFunction
' ----------------------------------------------------------------------------------------
Set AConnection = ADO.CreateADOConnection
AConnection.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=g8PBgbADQksh7WFSy+MDIbdZQyQ4g90h;Initial Catalog=ClientManager;Data Source=d1950SQL1"
AConnection.LoginPrompt = False ' Suppress the login dialog box
AConnection.Open
Dim RecSet
Set RecSet = AConnection.Execute_(varQuery)
MsgBox(RecSet.Fields(0).Value) ' Returns total number of records
Set fn_ExecuteQuery = RecSet
End Function