none
Unload Userform not working as expected (VBA) RRS feed

  • Question

  • Hello Friends

    I have two almost identical userforms on excel. The userform has a combobox that allows the user to toggle between two languages. If a user selects a language different from the initial selection on the combobox, the second userform should display and the first should close. On the second userform if the user selects the other language, the first userform should open again and the second should close.

    Here is my code for the two userforms:

    USERFORM1:

    Private Sub ComboBoxShona_Change()
        
         Select Case ComboBoxShona.Value
            Case "Shona"
            Case "English"
                Unload UserFormHome
               
                UserFormHomeEnglish.Show
                Exit Sub
                
        End Select
    End Sub

    where ComboBoxShona is the name of the combobox in Userform 1

    USERFORM 2:

    Private Sub ComboBoxEnglish_Change()
         Select Case ComboBoxEnglish.Value
            Case "English"
            Case "Shona"
                Unload UserFormHomeEnglish
                UserFormHome.Show
                Exit Sub
        End Select
    End Sub
    

    where ComboBoxEnglish is the name of the combobox for Userform 2.

    With this code, the system works well for a few toggles, but after a few successful attempts it gives error '400':

    Form already displayed; can't show modally.

    It seems one of the forms fails to close, although the unload command is present in both forms and would have worked in earlier toggle attempts.

    Someone please help!!! Thank you very much for your assistance.

    LWS

    Friday, October 28, 2016 9:33 AM

All replies

  • Hi,

    The code works fine for me and I didn’t get any runtime error. Do you set the model property for the two forms?

    According to Form already displayed; can't show modally (Error 400), I suggest you set vbModeless when using  Show Method.

    E.g.

    UserFormHome.Show 0

    UserFormHomeEnglish.Show 0

     

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 31, 2016 2:24 AM
    Moderator
  • Hi Celeste

    Thanks for the "vbModeless" idea. It's great!

    LWS

    Monday, October 31, 2016 6:20 AM
  • Hi,

    If your issue has been resolved, i suggest you Mark as answer to close the thread.

    If you have any other issues, please feel free to let us know.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 3, 2016 2:02 AM
    Moderator