Stepping through collections

Limitation

There is a limitation in the use of collections (COM API), and the GetFirst and GetNext methods (Classic API): You cannot access fields that come later in a form than the field that is currently being processed. Similarly, you cannot access forms that come later in a set than the form that is currently being processed. In other words, you cannot access a field or form that is not yet processed.

This is particularly true in Scan and Interpret, but also in Verify and Transfer.

This means that you must avoid:

Another limitation is that you cannot iterate over all forms in a set and then on one of the accessed forms start a new iteration over all forms in the same set again.

Workaround

If you want to step through all forms in a set, always do it in a set-level event rather than a field or form-level event. Some suitable events are:

Module

Events (set level)

Scan

SetScanEnd

Interpret

SetInterpreted or SetValidate

Verify

SetComplete

Transfer

SetTransferStart

 

If you want to step through all fields on a form, always do it in a form-level event, rather than a field-level event. Some suitable events are:

Module

Events (form level)

Scan

FormScanEnd

Interpret

FormInterpreted or FormValidated

Verify

FormComplete

Transfer

FormTransferStart

 

If you still need to collect some fields in a field-level event, then use the following general rule:

If you access fields through the Application.Form object, check if Field is the same as Application.Field. This is done as follows:

 

Set objField = Application.Form.GetFieldByName("MyField", 0)

If objField.FieldNo = Application.Field.FieldNo Then

    Set objField = Application.Field ' Replace with Application.Field

End If