I have a question regarding instances of userforms.
When a userform is constructed via an object in a module (e.g. set frm = new Userform2) can I hide it and restore it by the show method even when the sub is run until the end?
Let's say:
- userform creation by sub1
- entering values to the userform
- hiding the userform with sub2
- restore userform with all values by sub3 with the show method
I got really strange behavior when testing code with show and hide methods on module level or Userform Code but what I got finally to work is that using a global variable and the following code in a standard module:
Global frm As UserForm2
Option Explicit
Sub sub1()
Set frm = New UserForm2
With frm
.Show vbModeless
End With
End Sub
Sub sub2()
With frm
.Hide
End With
End Sub
Sub sub3()
With frm
.Show vbModeless
End With
End Sub
It's often said that global variables should be avoided. Is it even possible here? Do I miss something?
Public/Private f As UserForm1and maybe a sub for the showing part to ensure consistent "showing" It would be better maybe if the form also checked the existience offrmon opening, so if run from F5, and to make sure the sub2 and 3 have an object to operate on..Hideing at a Module Level, instead of as part of the UserForm? Also, if you justUserForm2.Show, you can show the existing instance, with no need to create aNew UserForm2at any point