Results 1 to 3 of 3

Thread: Unload a userform

  1. #1
    100 Club
    Join Date
    2008-02
    Posts
    112
    Login to Give a bone
    0

    Default Unload a userform

    I have a user form that has a toggle button which activates(shows) another userform with the following code

    Code:
    Private Sub tglSubLog_Click()
    
    fmSubLog.Show
    
    End Sub
    and laters acts as a condition check in my code. In the second userfrom I have a command button for Cancel which has code in a commandbutton_Click routine.

    Code:
    Private Sub cmdCancel_Click()
    'close fmSubLog
    Unload Me
    'reset Insert Submittal Log toggle button to false
    fmSheetBuilder.tglSubLog.Value = False
    
    End Sub
    in order to to completely close the userform with this as the cancel code I have to hit the cancel button twice.

    if I write that same code like this;

    Code:
    Private Sub cmdCancel_Click()
    
    'reset Insert Submittal Log toggle button to false
    fmSheetBuilder.tglSubLog.Value = False
    'close fmSubLog
    Unload Me
    
    End Sub
    I get a "Runtime error 400: Form already displayed; can't show modally." I understand what is happening in the code it is looking at the change to false under the cancel code and reading that as a click it and trying to show the userform a second time.

    Now this was working fine last week, today it is not, how can I fix this.

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: Unload a userform

    In the first format of cmdCancel, after you unload the form, nothing beyond that is going to execute. So setting the value on the other form didn't cause an error.

    As to your second scenario, a change to false can't cause the Click event to fire. It could only fire an onChange event, but I don't recall if a button has such an event. The problem is that you can't access a form while its in the background and a modal form is active. Its the same as if you clicked outside the form. Windows would play that nice thunk sound. What you need to do is place the toggle code right after you you show the form. This is where code execution returns after the form is closed.
    C:> ED WORKING....


    LinkedIn

  3. #3
    100 Club
    Join Date
    2008-02
    Posts
    112
    Login to Give a bone
    0

    Default Re: Unload a userform

    THank you for the input I figured out what I needed to add to accomplishe my goal about 2 minutes before you replied to my post.

Similar Threads

  1. Parameters from Userform
    By CADfunk MC in forum VBA/COM Interop
    Replies: 2
    Last Post: 2010-04-26, 06:25 PM
  2. All I want is a Userform to show..
    By Coolmo in forum Dot Net API
    Replies: 5
    Last Post: 2009-07-23, 02:03 PM
  3. VBA userform in excel
    By Streng in forum VBA/COM Interop
    Replies: 3
    Last Post: 2009-02-17, 07:02 PM
  4. Userform limit
    By Coolmo in forum VBA/COM Interop
    Replies: 8
    Last Post: 2007-06-22, 06:29 PM
  5. Userform sizing
    By Coolmo in forum VBA/COM Interop
    Replies: 7
    Last Post: 2006-05-30, 11:30 PM

Posting Permissions

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