Word Form with ActiveX button opens another Word Form w/Restrictions RRS feed

  • Question

  • I have a basic form in Word. I inserted an ActiveX button to open another Word form based on if a date field is entered. If the date field is not entered, the button will not work. I know where to put the code, but have no idea how to write the code.  I appreciate any feedback I can get.

    Thank you in advance!!!

    Wednesday, January 25, 2017 1:35 PM

All replies

  • Are you referring to a Userform or a form you created to be filled out in Word? If a Userform then the following code.

    Firstly create the CommandButton and then in Design Mode, set the Enabled property to False

    Then Private Sub TextBox1_AfterUpdate will run after something is entered in the TextBox and it tests for a valid date and if valid then the command button is enabled.

    The code attached to the command button then checks again that textbox1 contains a valid date before it will show Userform2.

    Private Sub TextBox1_AfterUpdate()
        If IsDate(Me.TextBox1.Value) Then
            Me.CommandButton1.Enabled = True
            Me.CommandButton1.Enabled = False
        End If
    End Sub

    Private Sub CommandButton1_Click()
        'The test for date in TextBox1 is probably superfluous
        'but is a double check that Userform2 cannot be opened without the valid date
        If IsDate(Me.TextBox1.Value) Then
        End If
    End Sub

    Regards, OssieMac

    Friday, January 27, 2017 2:11 AM