Passing a record to a function

G

Guest

Hi,

I have a large sub that I need to break down, so I am trying to pass an open
record to a function and get the record back... with the contents altered by
the funtion. I am getting a Invalid Use of Property error. Is it possible
to do what I am trying??? Here is a stripped down code snipit of the Sub and
Function. Thx - Mike

' code snipit
Public Sub MainRoutine
Dim cn As ADODB.Connection, rcdPPrice As New ADODB.Recordset
rcdPPrice.Open strSQL, cn, adOpenStatic, adLockReadOnly
rcdPPrice.MoveFirst
Do Until rcdPPrice.EOF
rcdPPrice = CallMyFunction( rcdPPrice )
rcdPPrice.MoveNext
Loop
End Sub

Public Function CallMyFunction( rcdPPrice As AODB.Recordset) As
ADODB.Recordset
' do some logic
CallMyFunction = rcdPPrice
End Function
 
G

Guest

If both procedures are in the same module, the easier way would be to scope
the table object variable reference at the module level. Then any function
or sub in the module will see the object.
 
G

Guest

I started all this because after adding additional logic to the procedure, I
recieved the Compile Error msg "Procedure To Large". Something about a 64k
limitation.

So I broke the procedure down and place most of the logic in two functions.
I can try to make three procedures in the same module. That may be easiest
if the 64k limitation is on the procedures themselfs and not on the modules.
 
G

Guest

If you have one procedure (sub or function) that is hitting the 64K limit, it
is waaaayyyy to big. You need to break it up.
 
G

Guest

Yes, I am working on breaking it up. The confusion I have is that there is a
ADODB.recordset that I am trying to figure out how to pass from Sub to
Function and back again. This will allow me to break up the processing into
Multiple functions.

Is it possible to pass a recordset around to different functions that update
the data, then have the functions return the records set? If so, would you
mind providing me the syntax. I can't seem to figure it out. Thx
 
G

Guest

You should be breaking it up into smaller subs and functions in the same
module. I don't think it is a problem with the module size.
Then if you do your dims for the recordset object varialbes in the top of
the module before any procedures, All the procedures in the module will have
visibility to the recordset, so it doesn't have to be passed.
 
G

Guest

Awesome! It worked wonderfully.

Thank you for the lesson in scope with Subs & Functions in Modules.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top