View Full Version : Solved: Hidden Userform
av8tordude
08-30-2012, 02:05 AM
Is there a way to determine if a userform is hidden?
Teeroy
08-30-2012, 02:34 AM
Use the userform.visible property. It is used to either test its status or change it.
av8tordude
08-30-2012, 02:47 AM
I understand the property, I think there is a difference between Hidden vs Unload. From my understanding, Hidden means its out of site, but the data on the userform can be used for other purposes. Unload means (I think) the data on the userform is lost.
Basically, I just want to know if one particular userform (AppType) is hidden.
I have this code, but it loops, therefore slows down other codes
Dim usrFrm As Object
For Each usrFrm In UserForms
If usrFrm.Name = "AppType" Then
MsgBox "Hidden"
End If
Next usrFrm
Hi Aviator,
Quickly tested, but for seeing if the form is loaded, maybe:
Option Explicit
Sub Setup1()
Load UserForm1
Load AppType
MsgBox IsLoaded("AppType")
Unload AppType
Load UserForm2
MsgBox IsLoaded("AppType")
End Sub
Function IsLoaded(UserFormName As String) As Boolean
Dim Count As Long
For Count = 0 To UserForms.Count - 1
If UserForms(Count).Name = UserFormName Then
IsLoaded = True
Exit For
End If
Next
End Function
For seeing if the form is loaded and showing/visible, maybe:
Sub Setup2()
Load UserForm1
Load AppType
MsgBox IsLoadedAndHidden("AppType")
Unload AppType
Load UserForm2
MsgBox IsLoadedAndHidden("AppType")
AppType.Show vbModeless
MsgBox IsLoadedAndHidden("AppType")
AppType.Caption = "It's me!"
Dim n As Long
For n = 0 To UserForms.Count - 1
MsgBox UserForms(n).Caption
Next
End Sub
Function IsLoadedAndHidden(UserFormName As String) As Boolean
Dim Count As Long
For Count = 0 To UserForms.Count - 1
If UserForms(Count).Name = UserFormName Then
If UserForms(Count).Visible Then
IsLoadedAndHidden = True
Exit For
End If
End If
Next
End Function
...see reason for editing...
I should have tacked in:
The above presumes forms named:
UserForm1
UserForm2
AppTypeFor what it is worth, you may wish to consider prefacing (notation) your variable names. 'frmAppType' might make easier sense a few months from now (or at least make sense quicker upon reading the code), when you go back and add or edit code.
BTW - you are correct as to Load(ed) vs Show(n). If your Load or Show the form, the Object Module is loaded. If you Hide the form, it still exists and any variables existing in it can still be used.
Hope that helps,
Mark
Teeroy
08-30-2012, 04:40 AM
If it's something you need regularly within your routine you could use an indicator (named range perhaps?) that changes state during the initialize and terminate events of the userform.
av8tordude
08-30-2012, 09:39 AM
Thanks you both. I think I will use the boolean procedure.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.