variables

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

This is PROBABLY really simple, but I'm missing 'it'...

I have several fields in the current row of the current
recordset that I want to use in a called procedure (same
module). They were 'empty' when I went to execute the
called procedure. So I created several variables in the
first procedure, set them to the fields I wanted, then
performed the called procedure. Now these variables are
empty.

I have a book that mentions a 'Declarations section', but
doesn't give any example. Of course, I'm ASSUMING that
this is what I need. So...

1.) Can I get the fields directly from the recordset
without saving the data first? If so, how?

or

2.) How do I get to access the values of variables set
in one procedure, in the called procedure? (The book I
have appears to indicate that I shouldn't be having the
problem I do. The data 'should' be available in the
called procedure.)

What am I missing?

Thanks so much, in advance,

Tom
 
Hi Tom

the Declarations section is right at the top of the module sheet - above the
first SUB where you (should) have the words Option Explicit ... if there's
nothing there, just type your Dim statements and it will be created for you.

Basically if you create (DIM) a variable within a sub then it is only
"alive" within that sub, if you declare it in the Declarations section then
it is able to be used between procedures within the module sheet.

Hope this helps
Cheers
JulieD
 
I am not sure of the description but if have something like:

Sub CalledSub(ByVal Arg1, ByVal Arg2, ...)
Do something with arguments
End Sub


Sub CallingSub()

' Create Recordset rs
' Call the other sub using Field values of the current Record of the
recordset
' Then you can simply use:

Call CalledSub(rs.Fields("Field1").Value, rs.Fields("Field2").Value,
....)

End Sub

The ".Value"'s above are not necessary since Value ids the default Property.
However, I like to use it explicitly for clarity.
 
Back
Top