form variable

  • Thread starter Thread starter smk23
  • Start date Start date
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
 
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
 
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.
 
Back
Top