Consulting

Results 1 to 5 of 5

Thread: Using two Userforms.

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    Using two Userforms.

    I have 2 userforms that work with each other.
    a cmdButton calls the other userform. What i want is for when the second form is closed to show userform1, but also be able to click the cmdbutton again to go back to userform2 if necessary and be able to close that one and go back to userform1.
    Hope that's not that confusing.

    I got this script that works nice from an earlier thread.

    UserForm2
    [VBA]Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = 0 Then

    UserForm1.Show
    End If
    End Sub[/VBA]
    Problem is if I click on the CmdButton on UserForm1 to call This userform2 it gives me
    RUN-TIME ERROR '400'
    FORM ALREADY DISPLAYED; CANT SHOW MODALLY

    Can someone help.

    Thanks

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    A review of what I said in that thread, http://vbaexpress.com/forum/showthread.php?t=21569 might be worthwhile. I had anticipated this issue there.

    Notice, that I gave two methods to verify that a userform was active. You can use the Visible property or the API method using FindWindow.

    e.g.
    If UserForm1.Visible=True then AppActivate UserForm1.Caption
    As discussed in that thread, you can use the UserForm1.Show method as well. However, it does reposition the dialog. Using Show will force the dialog to open if it is not open so that might be good or bad. The choice is yours.

    What is your ShowModal value for the userform? You can set it to True as I explained in that other thread if you want it modeless. Or, you can set it in the show like:
    UserForm1.Show vbModeless
    Using these concepts, you should be able to avoid the error.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Tuck the form away as you exit

    [vba]

    Private Sub cmdShowForm2_Click()
    Me.Hide
    UserForm2.Show
    End Sub

    [/vba]

    and do the same with form2

    [vba]

    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = 0 Then

    Me.Hide
    UserForm1.Show
    End If
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    I tried that xld but if I go back to userform2 the second time and click the red X it doesn't do anything.

  5. #5
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    Any Idea how to get around that?

Posting Permissions

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