Setting a value in modules

  • Thread starter Thread starter mike
  • Start date Start date
M

mike

Hi all,

how do I change a variable in the Module from a form?

For example:

In the module (name it module1)

Dim a as string //outside of all function

Public Function setvar(setstr as string)

a=setstr //error right here

end Function

Public Function getvar()
getvar= a

End Function


Then:
In a form, I click on a command button to set a=
something by using the function setvar(some string). But
it didn't work? Is there a better way to assign a value to
the variable a in the module??

mike
 
If the variables are defined Public, you can refer to them directly from
anywhere else.

So, in the module:
Public strMyVariable as string

Then from anywhere else (in or outside that module):
strMyVariable = "xyz"

In passing, I hope you are not really naming your variable 'a'! If so, you
need to change that pronto. Come up with a proper variable naming scheme, or
look at other developer's code to see how they do it. Variable names like
'a', 'b' etc. are guaranteed to make your code incomprehensible.

HTH,
TC
 
Back
Top