+ Reply to Thread
Results 1 to 10 of 10

Using If statement to ascertain if a userform is hidden

  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,622

    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,622

    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:
    Please Login or Register  to view this content.
    By default, it will be set to False. In the Initialisation code for the form, put
    Please Login or Register  to view this content.
    .

    And then, elsewhere, you can say
    Please Login or Register  to view this content.

    Regards, TMS

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

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

    Code to use userform3 from worksheet

    Please Login or Register  to view this content.
    from button on userform1 or userform2
    Please Login or Register  to view this content.
    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:

    Please Login or Register  to view this content.

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

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

    Please Login or Register  to view this content.

  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

    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.

  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

    Scratch that I figured it out by tweaking the initialisation code to
    Please Login or Register  to view this content.
    CHeers again

+ 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