When merging an iSeries report with a FormDocs form overlay, the best place for custom script code is in the Form_BeforePrint event. The Form_BeforePrint event is triggered before a page is printed. All form fields for the page are available to the VB script code, so the script can manipulate the data if needed. 
  • The FormDocs form object name for accessing fields in the current form is: Thisform
  • To access or modify field values in a form programatically, use the Fields collection object of Thisform. 
Because FormDocs acts as a full-fledged basic engine, most VB functionality is available, as well as the ability to call ActiveX/OLE enabled objects, such as ADO, to look up database information.
 
The following are some very simple examples of using VB scripting in form design during the Form_BeforePrint event:
Private Sub Form_BeforePrint (Device As fdPrintDevice, Cancel As Boolean)

 '-----------------------------------------------------------
 'This is an example of manipulating data in the FormDocs form
 'prior to printing the selected page.
 '
 'Notes:
 'Thisform is an object of type Form that refers To the currnet form. 
 'The "Fields" collection refers to all the fields on a form page.  
 '-----------------------------------------------------------

 Dim lcField As Field 'Declare field object work variable
 Dim lcWork As String 'Declare work variable to hold field in string format

 '-----------------------------------------------------------
 'Display a specific Message for one of the form fields
 '-----------------------------------------------------------
'Msgbox Thisform.Fields("InvoiceNo").Value

 '-----------------------------------------------------------
 'Iterate through all fields and display
 '----------------------------------------------------------- 
'For Each lcField In Thisform.Fields
'    MsgBox lcField.Name & lcField.Value 
'Next

 '-----------------------------------------------------------
 'Move invoice number to string field
 '-----------------------------------------------------------
 'lcWork = Thisform.Fields("InvoiceNo").Value

 '-----------------------------------------------------------
 'Place the prefix INV: in front of the invoice number
 'and modify the form values. 
 '-----------------------------------------------------------
 Thisform.Fields("InvoiceNo").Value =   "INV:" & Thisform.Fields("InvoiceNo").Value 

End Sub

 


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

Last Modified On: December 10, 2016