form variable

S

smk23

Is there a way to declare a variable whose scope is the entire form module?

For example, I want to set a form variable and not have to re-set it with
each procedure. I tried using a constant:

Private Const frm As Form= Me.frmBrCorrespondence2_Sub.form

as well as this in the form module header:

Dim frm as form
Set frm=Me.frmBrCorrespondence2_Sub.form

Neither approach flys. Is there a way to do this?

Thanks,
Sam
 
C

Cheese_whiz

Hi smk,

Are you sure you don't want just a string variable? Looking at what you are
trying to do, I think you need a string variable and it can go in the general
declarations area at the top of the form's module.

CW
 
D

Dirk Goldgar

smk23 said:
Is there a way to declare a variable whose scope is the entire form
module?

For example, I want to set a form variable and not have to re-set it with
each procedure. I tried using a constant:

Private Const frm As Form= Me.frmBrCorrespondence2_Sub.form

as well as this in the form module header:

Dim frm as form
Set frm=Me.frmBrCorrespondence2_Sub.form

Neither approach flys. Is there a way to do this?

Thanks,
Sam



Define the form variable at the top of the form module, in the Declarations
section. e.g.,

Option Compare Database
Option Explicit

Dim frm As Form

Then use the form's Open or Load event to set the value of the form
variable:

Private Sub Form_Open(Cancel As Integer)

Set frm = Me.frmBrCorrespondence2_Sub.Form

End Sub

Note that it's generally a good idea to use a naming prefix for module-level
variables, so that you can remember where they're declared and don't
unintentionally reuse the name. So it would probably be better to call you
variable "m_frm", or something even more descriptive.
 

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