Click to See Complete Forum and Search --> : Functions -> return values
sead
August 8th, 2000, 06:59 AM
Is this a valid code:
public Function FindIt(strTableName as string, strCriteria as string, strSearch as string) as ADODB.Recordset
' some code ...
End Function
Is it possible to return a recordset from a function or even call another sub/function like :
call MySub(rs As ADODB.RecordSet)?
If yes, how ?!?
Thanks
Lothar Haensler
August 8th, 2000, 07:13 AM
this is perfectly valid.
Your declarations look ok.
What exactly is your question?
Lothar Haensler
August 8th, 2000, 07:20 AM
here is a sample for a function that returns a recordset
private Sub Command1_Click()
Dim rs as ADODB.Recordset
set rs = getrs()
rs.MoveFirst
Do While Not rs.EOF
Debug.print rs.Fields(0).Name
Debug.print rs.Fields(0).Value
Debug.print rs.Fields(1).Name
Debug.print rs.Fields(1).Value
rs.MoveNext
Loop
rs.Close
End Sub
Function getrs() as ADODB.Recordset
Dim rs as ADODB.Recordset
set rs = new ADODB.Recordset
rs.Fields.Append "field1", adInteger
rs.Fields.Append "field2", adInteger
rs.Open
rs.AddNew
rs.Fields(0).Value = 1
rs.Fields(1).Value = 2
rs.AddNew
rs.Fields(0).Value = 3
rs.Fields(1).Value = 4
rs.Update
set getrs = rs
End Function
sead
August 8th, 2000, 08:01 AM
This is what i'm doing (or trying to do...):
I have a form 'frmSearch' where user can choose/input search-criteria from two comboboxes and one textbox. In frmSearch.CmdButton_Click event i'm validating appropriate values and if everything is OK then i'm calling a function:
call FindIt(strTableName, strCriteria, strSearch)
The FindIt(strTable,strCrit,strSearch) function is searching for the data and THERE is my ADODB.recordset which i want to pass to my Sub:
Sub ShowSearchData( rstRecSet As ADODB.RecordSet , lngCount as Long )
Here is my question:
- HOW to pass this RecSet to Sub?
I mean something like this:
' Somewhere in a "FindIt(x,y,z)" function ...
call ShowData(rstRecSet, lngRecordCount)
' idea was to pass RecordSet & RecordCount value
Sub 'ShowSearchData(arg1,arg2)' is determining if RecordSet.RecordCount = 1 or more records. Then I'm presenting a data in a separate form if it is only one record, or in a ListView Control if there is multiple records.
Thanks
Sead
P.S.
I hope that my description is not hard to understand, sorry for strange english
Lothar Haensler
August 8th, 2000, 08:11 AM
Yes, you can Dim the Recordset object in your FindIt procedure and pass it to ShowSearchData. No problem.
I'd rather use the GetRows method of the REcordset object instead of relying on the RecordCount property.
If you pass the result from GetRows (returns a two-dimensional array of rows and columns) you don't even have to pass the recordset object at all.
>sorry for strange english
no problem. I'm not a native English speaker, either.
sead
August 8th, 2000, 08:39 AM
You don't trust to RecordCount property !?! Why ?
Sead
Lothar Haensler
August 8th, 2000, 08:48 AM
because not all OLEDB providers support it. And sometimes it depends on the cursor location property.
Before you can safely use it, you should call the Supports method:
Supports (adApproxPosition) or Supports (adBookmark)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.