Tablefields – Kofax DOKuStar Validation User Manual

Page 43

Advertising
background image

DOKuStar Validation Programming Manual

Page

• 39

TableFields

Tables require additional features, because they are fields that are made up of rows, columns, and cells.

As an example, imagine a table in your document that has (among others) three columns

Quantity

,

SinglePrice

and

TotalPrice

. Whenever the user corrects a cell in the

Quantity

or

SinglePrice

column, the corresponding total price is recalculated (by:

Quantity

times

SinglePrice

) and compared

against the value in the

TotalPrice

column. If the values are different, the user shall decide whether to override

the total amount value or not.

Solution:

Option Explicit

Dim WithEvents Table As FieldType

Private Sub Application_OnProjectLoaded(ByVal App As Application)
Set Table = App.Project.DataSet.Schema.DocumentTypes("Invoice").FieldTypes("Table")
End Sub

Private Function Table_OnFieldChanging(ByVal Field As Field, ByVal SubField As Field, _
ByVal VerifyEventArgs As VerifyEventArgs) As Boolean
Dim t As TableField
Dim row As TableRow
Dim calculatedTotalPrice As Double
Dim totalPrice As Double

Table_OnFieldChanging = True
If SubField.Name = "Quantity" Or SubField.Name = "SinglePrice" Then
Set t = Field
Set row = t.row(SubField)
totalPrice = Val(row("TotalPrice").Value)
calculatedTotalPrice = Val(row("Quantity").Value) * Val(row("SinglePrice").Value)

If calculatedTotalPrice <> totalPrice Then
If MsgBox("Calculated total price: " & calculatedTotalPrice & vbCrLf & _
"Total price from column: " & totalPrice & vbCrLf & _
"Override?", vbYesNo) = vbYes Then
row("TotalPrice").Value = calculatedTotalPrice
Else
Table_OnFieldChanging = False

End If
End If
End If
End Function

Let us look at the interesting parts of the code:

First of all, a variable (

Table

above) is defined as for any other field and set accordingly:

Dim WithEvents Table As FieldType

Private Sub Application_OnProjectLoaded(ByVal App As Application)
Set Table = App.Project.DataSet.Schema.DocumentTypes("Invoice").FieldTypes("Table")
End Sub

Along with the event, the field and the sub-field come as parameters. The

Name

property of the sub-field delivers

the column name (as defined in the DOKuStar project), so you can ask if the cell is in one of the columns in
question:

If SubField.Name = "Quantity" Or SubField.Name = "SinglePrice" Then

Next, the generic

Field

must be converted to a specialized

FieldTable

variable:

Advertising