Public variables I guess

T

Ted

using a2k again....

i typically don't worry about the public-ity of variables but i think this
is one place where i want to...

i have a form and on my form i have a BeforeUpdateEvent wherein i declare a
variable Dim Flag as Integer which is bumpled up from its initial Flag = 0
setting every instance where a tested for condition is met. at the end of the
vba, if Flag > 0 then we docmd.runmacro a macro.

i also have an options group on this same form called Frame1 and i think i'd
like to have the value of Flag available to be tested in the AfterUpdateEvent
of Frame1's.

i tried declaring "Public Flag as Variant" atop the form's vba but when
using breakpoints i see that it's remaining empty.

can something be wrong?
 
M

mscertified

For things like that you can use a hidden control on the form. Just set
visible property to false.

-Dorian
 
O

Ofer Cohen

If this variable still declared on the Before update event of the form, it
will ignore the Global variable you declared in the Form, if that the case
you need to remove the second decleration in the Sub section.

You can initiate the variable to 0, when the form load
Public Const Flag As Variant = 0
 
T

Ted

hi dorian,

i don't understand this idea 'at all'. how would this tie in with what i
want to do?

-ted
 
T

Ted

Ofer,

puttting the following into the form's general declarations and after
commenting out the 'Flag = 0' from my BefUpdt

Option Compare Database
Option Explicit
Dim myvarOldValue As Variant
Public Const Flag As Variant = 0


results in the following 'message':

"Constants, fixed-length strings, arrays, user-defined types, and Declare
statements not allowed as Public members of an object module"

what's gone awry?

-ted
 
D

Dirk Goldgar

Ted said:
Ofer,

puttting the following into the form's general declarations and after
commenting out the 'Flag = 0' from my BefUpdt

Option Compare Database
Option Explicit
Dim myvarOldValue As Variant
Public Const Flag As Variant = 0


results in the following 'message':

"Constants, fixed-length strings, arrays, user-defined types, and
Declare statements not allowed as Public members of an object module"

what's gone awry?

Ofer mistyped. Instead of ...
Public Const Flag As Variant = 0

.... it should just be

Public Flag As Variant

Although I don't see any special reason to make Flag a Variant. It
seems to me that just complicates matters. Why not an Integer (as you
originally had it), or a Boolean?

Public Flag As Integer

or

Public Flag As Boolean
 

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