Kofax DOKuStar Validation User Manual

Page 12

Advertising
background image

DOKuStar Validation for Ascent Capture

Page

8

Here is the source code for this example:

Dim WithEvents Amount As FieldType

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

Private Function Amount_OnFieldChanging(ByVal Field As Field, ByVal SubField as Field, ByVal
VerifyEventArgs As VerifyEventArgs) As Boolean
Amount_OnFieldChanging = True 'Preset return value
If Val(Field.Value) > 1000 Then
If MsgBox("You entered a value > 1000. Please Confirm.", vbOKCancel) = vbCancel Then
Amount_OnFieldChanging = False 'User clicked cancel, so stay in the field
End If
End If
End Function

Let us go through this line by line:

Dim WithEvents Amount As FieldType

You define a variable

Amount

that shall be used in the VBA code. This variable has the type

FieldType

, which is

a notion from the

Schema

part of the

Dataset

. This variable shall get events (

WithEvents

), one of these

events is used below.

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

This subroutine will be called when the project is loaded, i.e. right after opening the batch. The only thing that is
done here is that you assign the variable

Amount

, which you defined above, to the right field type: set to the

FieldType

Amount

on the

DocumentType

Invoice

. The names you use here are the names from the

Ascent Capture definition: the form type

Invoice

has an index field

Amount

(to be more precise: form type

Invoice

is assigned to a document class which has an index field

Amount

).

Private Function Amount_OnFieldChanging(ByVal Field As Field, ByVal SubField As Field, ByVal
VerifyEventArgs As VerifyEventArgs) As Boolean

Defining this function enables to catch the

FieldChanging

event for the amount field: Whenever the user changes

the amount on an invoice, this function will be called and gets an Object

Field

as the first parameter, which is the

field itself. This object has the type

Field

, which is a notion from the

Data

part of the

Dataset

.

The function is expected to return a boolean; when returning

False

, the changing is aborted, i.e. the old value

(before the user typed his changes) is restored and the focus stays on this field. When returning

True

, the changes

are accepted, and the focus usually moves to the next field (the “usually” will be explained shortly).

Amount_OnFieldChanging = True 'Preset return value

The boolean return value is preset to

True.

If Val(Field.Value) > 1000 Then

Now take the

Field

received as a parameter and determine the field’s value. Since a value of a field is always a

string, the

Val

function is be used to convert to a double integer.

If MsgBox("You entered a value > 1000. Please Confirm.", vbOKCancel) = vbCancel Then
Amount_OnFieldChanging = False 'User clicked cancel, so stay in the field
End If

Open the message box. If the user hits

Cancel

, set the return value to

False

, thus aborting the change and

restoring the old contents.

Advertising