View Single Post
 
Old 07-24-2019, 08:27 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The first part is easy to do with legacy form fields, set the Order field property as a number field and check the calculate on exit check box. Insert the following where you require it using CTRL+F9 for the bracket pairs {}

{IF { Order } >=100 "Thanks" "The minimum order is 100 units"}. The fields will be calculated when you tab out of the order field when the form is protected.

The second part is much more complicated and requires the use of macros to unlock the form, insert the table and the fields it will contain and relock the form.

Frankly I would recommend the use of content controls rather than legacy form fields. For the first part use two text fields one titled Order and the other titled Response.
You can then use the following macro to establish which control has been filled and insert the required text

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim oCC As ContentControl
    Select Case ContentControl.Title
        Case Is = "Order"
            Set oCC = ActiveDocument.SelectContentControlsByTitle("Response").Item(1)
            If ContentControl.ShowingPlaceholderText = False And IsNumeric(ContentControl.Range.Text) = True Then
                If CInt(ContentControl.Range.Text) >= 100 Then
                    oCC.Range.Text = "Thanks"
                Else
                    oCC.Range.Text = "The minimum order is 100 units"
                End If
            Else
                oCC.Range.Text = ""
            End If
    End Select
lbl_Exit:
    Exit Sub
End Sub
You can add a further Case statement to the same macro to insert a table and further content controls as appropriate when the department is selected from a dropdown list control. You can fill that list from your Excel file.

See Insert Content Control Add-In with regard to the use of Editors and protection, converting the form to content controls and filling the list from Excel.

See attached example.
Attached Files
File Type: docm Order number Filled automatically.docm (36.9 KB, 6 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Last edited by gmayor; 07-25-2019 at 02:03 AM.
Reply With Quote