+ Reply to Thread
Results 1 to 8 of 8

Userform called from another userform textbox - unload problem

  1. #1
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Userform called from another userform textbox - unload problem

    Hello All

    I have a userform (Userform A) with a textbox.
    I am using the textbox to open another userform (Userform B) also with a textbox.
    The Textbox control doesn't have a 'Click_Event' so I am using the 'MouseDown_Event'.
    (I have also tried the Enter_event and Doubleclick_Event).

    (As it happens I want the contents of Userform B textbox to populate the Userform A (the calling) textbox - Userform B will be called from a number of textboxes)

    My problem is that when I Unload Userform B (with a command button) this 'closes' both Userform B AND Userform A.

    I need Userform A to remain open.

    Any advice on how I can achieve this please?

    With thanks.
    If this was helpful then please click the small star icon at the bottom left of my post. A little appreciation goes a long way.

  2. #2
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Userform called from another userform textbox - unload problem

    Hi.

    Try this code for closing Userform B only:

    Please Login or Register  to view this content.
    Click *, if my suggestion helps you. Have a good day!!

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Userform called from another userform textbox - unload problem

    that should not happen-what code are you using?

    I'd probably use the mouseup event though and restrict to a right click in case the user doesn't need the second form
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Userform called from another userform textbox - unload problem

    Hi,

    Have you tried "Private Sub UserForm_Click()" before? This is the click event for forms.

    As for making the second userform disappear, you can either 'Hide' the userform, or 'Unload' it from memory.

    So for example:

    Please Login or Register  to view this content.
    will hide Userform1 when you click on it.

    Hope this helps.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  5. #5
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Userform called from another userform textbox - unload problem

    Many thanks to abousetta, JosephP and jraj1106 for your responses.
    For completeness the code I am using is:

    UserformB call from textbox on UserformA (thanks to JosephP for your advice here)
    Please Login or Register  to view this content.
    and to unload/close UserformB
    Please Login or Register  to view this content.
    Nothing unusual I don't think; and I have nothing in the UserFormB_Query_Close event.

    However, for reference for others perhaps, I may have solved the cause without understanding why.

    I currently open (.Show) UserformA (which calls UserformB)as modeless.
    If I open UserformA as modal then the double-close problem I have disappears and UserformA remains Open - success.

    Whilst I didn't appreciate this at the time is this normal userform behaviour?


    However, thank you for your responses which of themselves help the thinking process.

    Barry

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Userform called from another userform textbox - unload problem

    Hi Barry,

    I almost always open my userforms in a modeless state. Some userforms open other forms and never had the problem you are mentioning. Maybe have both modal or both modeless and see if corrects the issue you are facing.

    abousetta

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Userform called from another userform textbox - unload problem

    I reckon your problem is that your with statement is trying to hold a reference to the form but you then unload it-perhaps simply
    Please Login or Register  to view this content.
    though I always suggest that a userform should not unload itself; it should merely hide and the calling code should take care of the clean-up

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Userform called from another userform textbox - unload problem

    Hi Barry,

    Thanks for marking the thread as Solved, but which solution ended up working for you?

    abousetta

  9. #9
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Userform called from another userform textbox - unload problem

    Hi Guys
    As a rich seam of discussion points and alternatives as usual.
    @ Abousetta
    My SOLVED solution as posted was to open UserformA as modal, this seemed to fix it.
    This was not a showstopper for my requirement so I was OK with that.

    However, testing JosephP's subsequent advice and removing the With/End With construct fixes the issue and still allows me to have UserformA modeless - Brilliant!

    Thanks again to all and to JosephP's insight.

    Barry
    Last edited by barryleajo; 03-27-2013 at 03:12 PM. Reason: fix error

+ 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