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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Calling a Form from a Form (Word VBA 2003+)

    Author
    Topic
    #452052

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #1114797

      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

      • #1114810

        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….

        • #1114811

          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).

    Viewing 0 reply threads
    Reply To: Calling a Form from a Form (Word VBA 2003+)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: