+ Reply to Thread
Results 1 to 4 of 4

Checking for User Form loaded

Hybrid View

  1. #1
    Registered User
    Join Date
    05-22-2008
    Posts
    74

    Checking for User Form loaded

    How can I test to see if a user form is loaded. If I try to access any item on the user form my code goes right into the form initialize to begin loading it. What I would like to do is test to see if the form is loaded.
    Scott
    The harder it gets the happier I am.
    Finally got my signature set up!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Quote Originally Posted by scottintexas
    How can I test to see if a user form is loaded. If I try to access any item on the user form my code goes right into the form initialize to begin loading it. What I would like to do is test to see if the form is loaded.
    Hi,

    Untested but perhaps something like:

    Sub IsLoaded()
        Dim stIsLoaded As String
            If UserForm1.Enabled = True Then
                stIsLoaded = "Loaded"
                Else
                stIsLoaded = "Not Loaded"
            End If
        MsgBox "Userform1 " & stIsLoaded
    End Sub

  3. #3
    Registered User
    Join Date
    05-22-2008
    Posts
    74
    Thanks for the reply.

    What I ended up doing is setting a global variable true when the form is loaded and false when unloaded so I can just check the variable. DUH!

    Again, thanks for your help.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello scottintexas,

    You can check if any forms are loaded by checking the Count property of the UserForms collection. The most recently loaded form is at index zero.
      FormsLoaded = UserForms.Count
    To check if a particular form has been loaded, you have to loop through the collection and check the form name. The UserForms collection object only accepts a number for the index. This code example returns the index number in the collection for the UserForm named "UserForm1"
      Dim Cnt As Integer
      Dim frm As Object
     
        For Each frm In UserForms
          If frm.Name = "UserForm1" Then
            MsgBox "UserForm1 is at index" & Str(cnt)
            Exit Sub
          End If
          Cnt = Cnt + 1
        Next frm
    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1