+ Reply to Thread
Results 1 to 6 of 6

Help with vbModeless

  1. #1
    Registered User
    Join Date
    07-17-2005
    Posts
    22

    Question Help with vbModeless

    Hi all,

    Well, I'm a complete VB newbie - and just trying to get a handle on things. I've sort of solved my problem, but was hoping someone could explain it to me (MS Help and Google have only confused me more!).

    I am delving into VB to try to build a quiz application in excel. In a nutshell, the user will navigate from form to form, with each form displaying a list of questions to answer.

    I've created the first form, which captures the user information (name and other info) and the second form - which will be an introductory explanation. Now I'm trying to add some navigation controls.

    I've made a "back" button on form2, which allows the user to navigate back. This generated the modal error, which I managed to fix by trial and error using vbmodeless command. Problem is I don't really understand what I have done!

    Could anyone explain the modal and modeless windows a little further to me?

    So far -

    Form1 launches from the excel worksheet using a button -

    Sub TakeMDLtest_Click()

    UserForm1.Show vbModeless

    End Sub


    Form 1 is

    Private Sub CommandButton1_Click()

    UserForm2.Show
    UserForm1.Hide

    End Sub

    And Form 2 is

    Private Sub CommandButton2_Click()

    UserForm2.Hide
    UserForm1.Show vbModeless

    End Sub

    EDIT: I've just realised that this actually does'nt display form1 when button 2 is clicked - so any help with this would really be appreciated!! I'm lost .....EDIT2: 5 minutes later and still lost. If I don't hide form1, then it works fine. But I only ever wan't one form to be visible. I'm gonna stop editing now...before I waste anymore space. O_o


    I've cut out any irrelevant code from my forms...and my navigation works fine like this. But I just need someone to confirm that this is right?

    My apologies about the length of this post for such a simple question - I'm sure as I learn more, I will also learn to keep things short and simple!

    Thanks for your help

    sys
    Last edited by systematic; 07-18-2005 at 10:12 AM.

  2. #2
    Registered User
    Join Date
    07-17-2005
    Posts
    22
    Instead of another edit....I have now got this working properly by running form2 as the modeless form. Would still dearly love an explanation or a link to further info!

    Thanks again.

  3. #3
    K Dales
    Guest

    RE: Help with vbModeless

    From Help: "When a UserForm is modal, the user must respond before using any
    other part of the application. No subsequent code is executed until the
    UserForm is hidden or unloaded."

    Modeless means you can do other things in Excel while the form is still
    showing.
    --
    - K Dales


    "systematic" wrote:

    >
    > Hi all,
    >
    > Well, I'm a complete VB newbie - and just trying to get a handle on
    > things. I've sort of solved my problem, but was hoping someone could
    > explain it to me (MS Help and Google have only confused me more!).
    >
    > I am delving into VB to try to build a quiz application in excel. In a
    > nutshell, the user will navigate from form to form, with each form
    > displaying a list of questions to answer.
    >
    > I've created the first form, which captures the user information (name
    > and other info) and the second form - which will be an introductory
    > explanation. Now I'm trying to add some navigation controls.
    >
    > I've made a "back" button on form2, which allows the user to navigate
    > back. This generated the modal error, which I managed to fix by trial
    > and error using vbmodeless command. Problem is I don't really
    > understand what I have done!
    >
    > Could anyone explain the modal and modeless windows a little further to
    > me?
    >
    > So far -
    >
    > FORM1 LAUNCHES FROM THE EXCEL WORKSHEET USING A BUTTON -
    >
    > -Sub TakeMDLtest_Click()
    >
    > UserForm1.Show vbModeless
    >
    > End Sub-
    >
    > FORM 1 IS
    >
    > Private Sub CommandButton1_Click()
    >
    > UserForm2.Show
    > UserForm1.Hide
    >
    > End Sub
    >
    > AND FORM 2 IS
    >
    > Private Sub CommandButton2_Click()
    >
    > UserForm2.Hide
    > UserForm1.Show vbModeless
    >
    > End Sub
    >
    >
    > I've cut out any irrelevant code from my forms...and my navigation
    > works fine like this. But I just need someone to confirm that this is
    > right?
    >
    > My apologies about the length of this post for such a simple question -
    > I'm sure as I learn more, I will also learn to keep things short and
    > simple!
    >
    > Thanks for your help
    >
    > sys
    >
    >
    > --
    > systematic
    > ------------------------------------------------------------------------
    > systematic's Profile: http://www.excelforum.com/member.php...o&userid=25294
    > View this thread: http://www.excelforum.com/showthread...hreadid=387984
    >
    >


  4. #4
    K Dales
    Guest

    Re: Help with vbModeless

    Because you have your .Show command before the .Hide command, you have an
    instant where both forms active which causes a conflict between the two modal
    forms. (You cannot Hide UserForm2 if UserForm1 has the focus, which it does
    when you show it).

    Another way to recitfy this would have been to reverse the order of the
    commands, i.e.:
    UserForm1.Hide
    UserForm2.Show

    --
    - K Dales


    "systematic" wrote:

    >
    > Instead of another edit....I have now got this working properly by
    > running form2 as the modeless form. Would still dearly love an
    > explanation or a link to further info!
    >
    > Thanks again.
    >
    >
    > --
    > systematic
    > ------------------------------------------------------------------------
    > systematic's Profile: http://www.excelforum.com/member.php...o&userid=25294
    > View this thread: http://www.excelforum.com/showthread...hreadid=387984
    >
    >


  5. #5
    jjk
    Guest

    Re: Help with vbModeless

    Hi,

    As Dales said with vbModal the user has to interact only with the
    active modal form.
    With vbModeless the user is free to interact with other forms or the
    excel workbook in the back.

    Now the reason you are getting the error is that you are using the
    module name to load and show the object.
    Let me rephrase.
    You are using Userform1.show.
    This means that for every call of that VBA would Load and then show the
    common object associated with the module. A better approach would be to
    create an object of the module load it and then show it. I guess some
    code will better demonstrate it.

    FORM1 LAUNCHES FROM THE EXCEL WORKSHEET USING A BUTTON
    --------------------
    Private Sub CommandButton1_Click()

    Dim frm1 As New UserForm1
    Dim frm2 As New UserForm2
    Load frm1
    Load frm2

    Do While True
    frm1.Show
    frm2.Show
    Loop

    Unload frm1
    Unload frm2

    End Sub
    ----------------

    FORM 1 IS
    ----------------
    Private Sub CommandButton1_Click()
    Me.Hide
    End Sub
    ----------------

    FORM 2 IS
    ----------------
    Private Sub CommandButton1_Click()
    Me.Hide
    End Sub
    ----------------


    I havent tested the code. This is at the present in an infinite loop.
    You can get out of it by hitting ctrl+Break.

    Another implementaion would be
    FORM1 LAUNCHES FROM THE EXCEL WORKSHEET USING A BUTTON
    --------------------
    Private Sub CommandButton1_Click()

    Dim frm1 As New UserForm1
    Load frm1

    frm1.Show

    Unload frm1

    End Sub
    ----------------

    FORM 1 IS
    ----------------
    Private Sub CommandButton1_Click()
    Dim frm2 As New UserForm2
    Load frm2
    frm2.Show
    Unload frm2
    End Sub
    ----------------

    FORM 2 IS
    ----------------
    Private Sub CommandButton1_Click()
    Me.Hide
    End Sub
    ----------------


    Hope this helps you understand modal forms better.
    Regards,
    Jayant


  6. #6
    Registered User
    Join Date
    07-17-2005
    Posts
    22

    Red face

    Thanks to all for your assistance. It is much clearer now!

    I really appreciate it!

+ 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