That property is actually WriteOnly. I ended up just making the optional parameter required and doing a call something like this:createDBF("Test", "c:\", Nothing)
I'm not sure if there's a better way to do it, or a better way to add additional fields, but it works. Any suggestions to improve it? Public Function createDBF(ByVal strName As String, ByVal strFolder As String, ByVal pFields As IFields) As ITable
' createDBF: simple function to create a DBASE file.
' note: the name of the DBASE file should not contain the .dbf extension
'
On Error GoTo EH
' Open the Workspace
Dim pFWS As IFeatureWorkspace
Dim pWorkspaceFactory As IWorkspaceFactory
Dim fs As Object
Dim pFieldsEdit As IFieldsEdit
Dim pFieldEdit As IFieldEdit
pWorkspaceFactory = New ShapefileWorkspaceFactory
fs = CreateObject("Scripting.FileSystemObject")
If Not fs.FolderExists(strFolder) Then
MsgBox("Folder does not exist: " & vbCr & strFolder)
Exit Function
End If
pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0)
' if a fields collection is not passed in then create one
If pFields Is Nothing Then
' create the fields used by our object
pFields = New Fields
pFieldsEdit = pFields
pFieldsEdit.FieldCount_2 = 2 'Add 2 fields
'Create First Field
Dim pField0 As IField
pField0 = New Field
pFieldEdit = pField0
With pFieldEdit
.Length_2 = 30
.Name_2 = "TextField0"
.Type_2 = esriFieldType.esriFieldTypeString
End With
pFieldsEdit.Field_2(0) = pField0
'Create Second Field
Dim pField1 As IField
pField1 = New Field
pFieldEdit = pField1
With pFieldEdit
.Length_2 = 30
.Name_2 = "TextField1"
.Type_2 = esriFieldType.esriFieldTypeString
End With
pFieldsEdit.Field_2(1) = pField1
End If
createDBF = pFWS.CreateTable(strName, pFields, Nothing, Nothing, "")
Exit Function
EH:
MsgBox(Err.Description, vbInformation, "createDBF")
End Function