Using Forms Scripting

To use forms scripting, you use the FormDocs Automation Basic Editor:
  1. Open the FormDocs Designer.
  2. Open a FormDocs form template or create a new form.
  3. In the menu, choose Tools > Forms Automation Basic Editor.

    Note: You can also open the FormDocs Automation Basic Editor by pressing Alt + F11.

    The FormDocs Automation Basic Editor opens.

  4. In Automate this Object, choose Form.
  5. In Program this event, choose BeforePrint.
  6. In the main window, write your script after the line Private Sub and before the line End Sub.

  7. To use this scripting editor:
    • In View Language Reference, you can see references to the different functions that you can use from Visual Basic. When you highlight a function in the list, information about that function and its syntax displays to the right. Double-click the function to paste the function name into your script at the cursor location.
    • In View Object Model Reference, you can see a list of the different objects available to reference directly in your script. The constants for each object are listed below.

Scripting 101

When you reference an object in your script, first reference your form object and then select "child" objects from there.
For example: To assign the string "This is only a test." to the field "TEST", first reference the form, then the field (among a list of all the fields), and finally reference the value of the field:
ThisForm.Fields("TEST").Value = "This is only a test."
Place a single quote (') before comments. The comment will continue until the end of the line. You can use comments to hide part of a script that you do not wish to use, but do not want to delete in case you need it later. Hiding part of the script in a comment is often used to add extra code for testing and debugging your script.
For example:
'Assigning our string to the TEST field.
ThisForm.Fields("TEST").Value = "This is only a test."

Scripting Samples

Below are a few basic scripting examples. Contact RJS Technical Support for further samples, simple questions on your scripting, or to get a quote for RJS Software write the script for you.

Example 1: Page Turning

Page Turning is ideal for forms that contain Terms & Conditions or forms where the last page varies slightly from the previous pages.
' Setup conditions for turning on pages using a
' simple IF-ELSE condition statement.
' NOTE: Form names and page names will vary for each
' form developer.  Please ensure that you change the
' script to match those names.
If trim(ThisForm.Fields("TriggerField").Value) = "My Trigger Value" Then

'Enable Page 1 and Disable Page 2
ThisForm.Pages("FormPage_1").Printable = true
ThisForm.Pages("FormPage_2").Printable = false


'Disable Page 1 and Enable Page 2
ThisForm.Pages("FormPage_1").Printable = false
ThisForm.Pages("FormPage_2").Printable = true

End If

Example 2: Copying Fields From One Page to Another

Assigning Fields from one page to another typically works best with page turning, when you have two nearly identical pages except for a few stray fields and do not want to keep re-mapping the fields in the Text Layer Designer.
' This script will copy the value from each field
' on a page to a corresonding field on a different
' page in the same form.

' I am forced to assume that you are using logical
' names for each field on each page.  For example if
' a field is named "Test" on page one it would be
' named "Test_2" on page 2, "Test_3" on page 3 and so
' on and so forth.  Fields that are unique to specific
' pages must still be mapped.

' Declare a Field object - this will be a working variable
Dim lcField As Field

' Loop through each field on page one and copy the value
' to the same field on page 2
For Each lcField In ThisForm.Pages("FormPage_1").Fields

'Make sure that there is not already a value in that field...
If ThisForm.Fields( + "_2").value = "" Then

' This is VERY important.  If a field exists on page 1 and not on page 2,
' the merge will fail unless this next line is here.
On Error Resume Next

' This next line may not be needed, if you are scripting
' logo images or barcode images, you must activate the field first.
ThisForm.Fields( + "_2").activate

' Assign the value
ThisForm.Fields( + "_2").value = ThisForm.Fields(

' End If Statement
End If

' Get next Field and repeat the loop...

Example 3: Specifying a Print Tray For One Page of the Form

To set a page to print on a specific printer tray:
  1. Find the Printer Tray number for your printer.

    Since Print Tray Numbers are not always consistant from printer to printer (and occasionally from print driver to print driver), you may want to download the following utility to help you identify the Print Tray Number for your printer:
  2. Find or choose the name of your form page: In the FormDocs menu, choose Page > Page Properties. The General tab displays the current page name. If you have not done so, enter a name for the page that you will remember.

    Note: Each page has a unique name.
  3. Open the FormDocs Automation Basic Editor and add code similar to the code below for each page that you want to send to a different print tray:

    ThisForm.Pages("page name").PrintPaperTray = TrayNumber

Example 4: Password Protecting Merged PDFs

  1. In the FormDocs Automation Basic Editor, under Form > Open, set a global password:

    Private Sub Form_Open (Cancel As Boolean)
    ThisForm.PDFOptions.OwnerPassword = "password"
    ThisForm.PDFOptions.OwnerPassword = ""
    End Sub

    Note: If you set the GOD password but not the user password, there will be no password protection, but the PDF will be encrypted.
  2. In Form > BeforePrint, set a variable password for the recipient:

    ThisForm.PDFOptions.UserPassword = "testing"

Still have questions? We can help. Submit a case to Technical Support.

Last Modified On: September 11, 2020