A common mistake when adding new fields to a geodatabase object is specifying a field name that is not supported by the underlying dbms system. Each database system has a list of reserved sql words that cannot be used when naming columns. This sample is an example of how to use the FieldChecker interface to validate a collection of fields.
How to use
- Paste the code into your VB or VBA Application.
- Call the function from within your application.
Public Function checkFields(pFieldsToTest As IFields, validateWorkspace As IWorkspace, _
ByRef fixedFields As IFields) As IEnumFieldError
'Note that if there are no errors the returned object will be nothing and
'the calling function should check for this
On Error GoTo EH
Dim pFieldChecker As IFieldChecker
Dim outEnumFieldError As esriGeoDatabase.IEnumFieldError
Set checkFields = Nothing
' create the field checker object
Set pFieldChecker = New FieldChecker
' notify the field checker which workspace to validate against
Set pFieldChecker.validateWorkspace = validateWorkspace
' validate the fields.
pFieldChecker.Validate pFieldsToTest, outEnumFieldError, fixedFields
' if there are no errors then exit
If outEnumFieldError Is Nothing Then Exit Function
Set checkFields = outEnumFieldError
Exit Function
EH:
MsgBox Err.Description, vbInformation, "checkFields"
End Function