beautypg.com

Check all fields before closing the batch – Kofax DOKuStar Validation User Manual

Page 104

background image

DOKuStar Validation for Ascent Capture

Page

100

Check All Fields Before Closing the Batch

When the user closes a batch, you might want to check if there all still erroneous fields.

You place such a check in the

Data

objects

OnPreExporting

event.

In the following example, all fields are checked if they have the state

Empty

or

Error

. If so, exporting is aborted

and the first field of this kind is activated. As you can see from the code,

TableFields

require special processing,

because we want to check the state of all the sub-fields and not the state of the

TableField

itself.

Option Explicit

Dim WithEvents dat As Data

Private Sub Application_OnProjectLoaded(ByVal App As Application)
Set dat = App.Project.DataSet.Data
End Sub

Private Function dat_OnPreExporting(ByVal Data As Data, ByVal Mode As ExportMode) As Boolean
dat_OnPreExporting = True

'* Search for empty and error states
If CheckAllFieldStates(Data, StateEmpty Or StateError) = True Then
MsgBox "Batch still contains fields to be processed"
dat_OnPreExporting = False
End If
End Function

Private Function CheckAllFieldStates(Data As Data, targetStates As State) As Boolean
Dim doc As Document
Dim fld As Field
Dim table As TableField
Dim row As TableRow
Dim cell As Field

CheckAllFieldStates = True
For Each doc In Data.Documents '* cycle through all documents
For Each fld In doc.Fields '* cycle through all fields

If fld.FieldDescriptor.FieldClass.Name = "TableField" Then
Set table = fld '* if it vis a table, check for all cells
For Each row In table.Rows
For Each cell In row
'* compare the cell's state to those searched for
If (cell.State And targetStates) <> 0 Then
table.Activate '* Found: Activate table and cell
cell.Activate
Exit Function
End If
Next cell
Next row
Else
'* compare the field's state to those searched for
If (fld.State And targetStates) <> 0 Then
fld.Activate '* Found: Activate it
Exit Function
End If
End If
Next fld
Next doc
CheckAllFieldStates = False
End Function