
Originally Posted by
Max187Boucher
if you keep the variables in your form code (NOT MODULE) it will never be global it stays public in the form itself
That's not entirely true - form's public variables and properties retain values even after form's been unloaded.
See quick sample below:
Code:
'form1 code
Option Explicit
Dim iTest As Integer
Public Test2 As Integer
Private Sub Form_Load()
Test1 = -1
Test2 = -1
Form2.Show
End Sub
Private Sub Form_Unload(Cancel As Integer)
Test1 = 99
Test2 = 88
End Sub
Public Property Get Test1() As Integer
Test1 = iTest
End Property
Public Property Let Test1(ByVal iNewValue As Integer)
iTest = iNewValue
End Property
'form2 code:
Option Explicit
Private Sub Command1_Click()
MsgBox "Form public property value: " & Form1.Test1
MsgBox "Form public variable value: " & Form1.Test2
End Sub
1. Run project: both public property (Test1) and public variable (Test2) get value of -1
2. Click button on Form2 to display their respective values (each should have -1_
3. Close Form1
4. Click button on Form2 again (you should get 2 msgbox's displaying 99 and 88)...