Using fields set up as Global in a module

  • Thread starter Thread starter Gavin Webb
  • Start date Start date
G

Gavin Webb

I have created a module with just three lines:

Global intSecLevel As String
Global strUserName As String
Global strPassword As String

In a form, I populate these fields with values, but when
that form closes and I open a second form, the fields are
empty and I can't see the data put there in the first form.

Have I set up the Global fields in the right way?
Why don't the fields keep their contents between the first
and second forms?
I've tried changing the first form to Visible=False
instead of closing it, but the fields still lose their
contents when I look at them from the 2nd form.

How can I keep the data in fields I can address from
within the whole 'project'/database.

Thanks
 
Use 'Public' instead of 'Global'.

I think you're just confusing terminology with syntax.
Public variables have global scope.
 
Gavin said:
I have created a module with just three lines:

Global intSecLevel As String
Global strUserName As String
Global strPassword As String

In a form, I populate these fields with values, but when
that form closes and I open a second form, the fields are
empty and I can't see the data put there in the first form.

Have I set up the Global fields in the right way?
Why don't the fields keep their contents between the first
and second forms?
I've tried changing the first form to Visible=False
instead of closing it, but the fields still lose their
contents when I look at them from the 2nd form.

How can I keep the data in fields I can address from
within the whole 'project'/database.

Thanks


If you put them at the top of a standard module, after the Option
Explicit line, and call them Public rather than Global, they should
hold their values, unless they are Dim-ed anywhere else in your code.

hth

Hugh
 
Back
Top