+ Reply to Thread
Results 1 to 10 of 10

Using If statement to ascertain if a userform is hidden

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Using If statement to ascertain if a userform is hidden

    Hi I have 2 userforms that call up a third userform via a command button in each form if certain criteria within each is met.

    THe third userform can also be called up using a command button on the main worksheet.

    WHen I call the third userform up via the 2 userforms I user userform1.hide or userform2.hide to hide the initial userform.

    When I have completed the task in the third userform and click clear I need the following to happen:

    1) if I called userform 3 from the worksheet I unload the sheet and return to worksheet,
    2) if I called userform 3 from userform 1, I unhide userform 1 and unload userform 3
    3) if I called userform 3 from userform 2, I unhide userform 1 and unload userform 3

    Is there an if statement whereby I can state If userform 1 has been initialised but hidden then do.... etc etc.

    Any help is meuch appreciated.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,776

    Re: Using If statement to ascertain if a userform is hidden

    You should be able to check the .visible property of the form for True or False. As for whether it's initialised, you might need to set your own flag when you execute the initialisation code.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Using If statement to ascertain if a userform is hidden

    thanks for reply. How would I go about setting my own flags?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,776

    Re: Using If statement to ascertain if a userform is hidden

    Define a public boolean variable outside the code, that is, at the top of standard module before the subroutines or in its own module.

    For example:
    Public bForm1Initialised As Boolelan
    By default, it will be set to False. In the Initialisation code for the form, put
    bForm1Initialised = True
    .

    And then, elsewhere, you can say
    If bForm1Initialised  Then ...

    Regards, TMS

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,448

    Re: Using If statement to ascertain if a userform is hidden

    Code to use userform3 from worksheet

    Sub FromWorksheet()
        
        Dim frmU3 As UserForm3
        
        Set frmU3 = New UserForm3
        frmU3.Show
        Unload frmU3
        Set frmU3 = Nothing
        
    End Sub
    from button on userform1 or userform2
    Private Sub CommandButton1_Click()
    
        Dim frmU3 As UserForm3
        
        Set frmU3 = New UserForm3
        Me.Hide
        frmU3.Show
        Unload frmU3
        Set frmU3 = Nothing
        Me.Show
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Using If statement to ascertain if a userform is hidden

    Genius - cheers for your help. THat code worked perfectly. If you have the time could you please look at my understanding of your code and fill in the blanks. Cheers again:

    
    Private Sub CommandButton1_Click()
    
        Dim frmU3 As UserForm3 ' define userform3 as frmu3
        
        Set frmU3 = New UserForm3 ' not sure on this step in code
        Me.Hide ' hide current userform
        frmU3.Show 'show userform 3
        Unload frmU3 ' unload userform 3 - is this only triggered once the unload me code is ran within the userform 3 sequence????
        Set frmU3 = Nothing ' again not sure on this 
        Me.Show ' show original form again
        
    End Sub

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,448

    Re: Using If statement to ascertain if a userform is hidden

    Private Sub CommandButton1_Click()
    
        Dim frmU3 As UserForm3 ' define userform3 as frmu3
        
        Set frmU3 = New UserForm3 ' load instance of userform3 into memory
        Me.Hide ' hide current userform
        frmU3.Show 'show userform 3
        Unload frmU3 ' unload userform 3 - is this only triggered once the unload me code is ran within the userform 3 sequence????  Yes 
        Set frmU3 = Nothing ' release object from memory
        Me.Show ' show original form again
        
    End Sub

  8. #8
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Using If statement to ascertain if a userform is hidden

    Many thanks for your replies. Will mark as solved.

  9. #9
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Using If statement to ascertain if a userform is hidden

    Scratch that I figured it out by tweaking the initialisation code to
     
    
      Dim Category As Variant
       If PottingForm.CategoryLst <> "" Then
       Category = PottingForm.CategoryLst
         Else
         
         Category = ActiveSheet.Cells(4, 3)
         End If
    CHeers again

  10. #10
    Forum Contributor
    Join Date
    12-14-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    106

    Re: Using If statement to ascertain if a userform is hidden

    Hi Andy. Sorry one last thing that I don't think warrants a new thread so thought would ask here. ON userform 3 I have a textbox that is populated on inialisation. THis will be populated via a link to specified cell if accessed through the worksheet click button or via a value of a listbox in userofrm 1 or 2.

    How can I amend your above code to make this happen or is it best done at a different step in the code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How do you close a window with a hidden UserForm in it?
    By skysurfer in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-16-2010, 07:58 PM
  2. showing the userform again when userform hasn't been hidden or unloaded
    By stanigator in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2007, 09:33 PM
  3. How to evoke a hidden userform?
    By Flippi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2006, 07:30 AM
  4. How to ascertain path of file in adjacent directory hierarchy
    By Paul Martin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-09-2005, 01:05 AM
  5. differentiate between a visible and a hidden userform
    By RB Smissaert in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2005, 06:05 PM

Tags for this Thread

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