Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New York
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling a Form from a Form (Word VBA 2003+)

    Is this possible? I believe I've seen it discussed, but couldn't find any topics with search.

    I have a form that loads and steps through a document looking at each page. If this then insert that.

    I would like to have a check box that instead of automatically inserting that if this, would load a second form for user confirmation.

    The loop in FormA needs to wait for the completion of the user action in FormB.

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    New York
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling a Form from a Form (Word VBA 2003+)

    Thanks, Hans.

    I don't want to use a msgbox as FormB would allow the user to adjust the insertion point up and down a line before clicking OK, returning to FormA, where it would do the actual insertion of the text .

    So, FormB is not just confirming the insertion of text, but the location of the insertion.

    I assume you meant intResult to be 1 for the OKClick and 0 for the CancelClick....

    Both forms should be left Modal?

    Should FormA be hidden while FormB is up?

    I will experiment with your suggestion. I think the main thing I overlooked was creating the public variable to contain the result of FormB....

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calling a Form from a Form (Word VBA 2003+)

    Yes, that's possible, although a message box (MsgBox) would be easier if you only want to ask for confirmation.

    A userform is modal by default, i.e. the user can't click in another userform or in the document, the user has to close the form.

    Basic idea:

    - Define a variable in a standard module:

    Public intResult As Integer

    - Set the value of intResult from the second userform depending on the choice made by the user, for example:

    Private Sub cmdCancel_Click()
    intResult = 0
    Unload Me
    End Sub

    Private Sub cmdOK_Click()
    intResult = 1
    Unload Me
    End Sub

    - Use the value of intResult in your code on the first userform:

    FormB.Show
    Select Case intResult
    Case 0
    ...
    Case 1
    ...
    End Select

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calling a Form from a Form (Word VBA 2003+)

    Yes, I should have used intResult = 1 in cmdOK_Click; I have edited my previous reply to correct it.

    You can hide FormA while FormB is up and show it again when FormB is closed, but it's not necessary - it's a matter of aesthetics and preference.

    If you want the code on FormA to pause while FormB is open, FormB should be modal (the default).

Posting Permissions

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