Passing Variables

A

AJ

In one of my 'form class objects (_afterupdate) I open a recordset.

In another part of my form, I run a module (publc sub) for my main
procedure. I would like to use some of the values from the recordset in my
main module but am having trouble passing that value. Is this possible? Where
do I need them defined or how?

I have found a awful workaround but would like to do it the correct way. Any
help (and proper syntax) would be great!
Thank in advance.
 
K

Ken Snell \(MVP\)

Can you post the VBA code so that we can see what you're doing?

There are different ways this can be done:
-- set a global, public variable to the desired value, and use that
variable in the main module;
-- pass the value as an argument in a call to the procedure in the main
module;
-- write the value into an invisible textbox on the form with the main
module, and let the main module read the value from that textbox;
and so on.
 
A

Armen Stein

In one of my 'form class objects (_afterupdate) I open a recordset.

In another part of my form, I run a module (publc sub) for my main
procedure. I would like to use some of the values from the recordset in my
main module but am having trouble passing that value. Is this possible? Where
do I need them defined or how?

I'm not sure you need to "pass variables". Perhaps you just need to
have the recordset object available to the main module. You can DIM
the recordset at the module level (at the top, before the first
Function or Sub) and use it throughout your module.

Armen Stein
Microsoft Access MVP
www.JStreetTech.com
 
A

AJ

I am new to access so I am not sure I am expalining it correctly. I think I
need to share it between modules. It looks like access created a module for
the form controls (on focus, on change, on dirty, etc.) and another one for
the main vba procedure.
 
L

Larry Linson

AJ said:
I am new to access so I am not sure I am expalining
it correctly. I think I need to share it between modules.
It looks like access created a module for the form
controls (on focus, on change, on dirty, etc.) and
another one for the main vba procedure.

You are correct... each form has a class module, with provision for the
event code (though not every event needs code). We usually do not have
multiple instances of a given form open in Access, but it is possible, and
if we do, each instance will have its own instance of the class module --
you don't have to know or do anything special to get this; it's just "the
way it is". Reports also have a similar class module.

Code in a form's module is only available when that form is Open, so
generally it contains the event code, perhaps some VBA code, constants, and
variables that are not event-related, but are local to the form or report.

Access does not automatically create a "main vba procedure". (If you began
with a template, it may have done so.) You can create separate standard
modules to contain vba functions and procedures that you want to access from
more than just one form (or from more than just one report).

You can also, if your thinking is primarily object-oriented, implement your
own separate class modules -- most of us do not implement our own class
modules in Access applications, even though we may do so in other languages
(C#, VB.NET, C++, etc.)

Larry Linson
Microsoft Office Access MVP
 

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