Sub FieldCreateInExistTableUni(dbs As Database, tdf As TableDef, strFldName As String, Optional lngType As Long = dbText, Optional intSize As Integer = 0, Optional intPosition As Integer = 0, Optional strIdxName As String = ""
'This procedure create new field in the existing table,
'create new index if it is need
'and set the position of new field in the table.
'If you'll omit optional parameters (lngType or/and intSize,
'its will be created new field with type "Text" and size=50.
'If you'll omit optional parameter index for this field
'index will be not created
Dim fld As Field
Dim idx As Index
Dim prp As Property
Dim i As Integer
'Create new field
If lngType = dbText Then
If intSize = 0 Then
intSize = 50
End If
Set fld = tdf.CreateField(strFldName, lngType, intSize)
ElseIf lngType <> 0 Then
If intSize = 0 Then
Set fld = tdf.CreateField(strFldName, lngType)
End If
Else
Set fld = tdf.CreateField(strFldName)
End If
tdf.Fields.Append fld
tdf.Fields.Refresh
'Change new field's position in the table
If intPosition >= tdf.Fields.Count Then
intPosition = 0
End If
If intPosition <> 0 Then
Set prp = fld.Properties("OrdinalPosition"
prp.Value = intPosition
End If
'Create index of new field
If strIdxName <> "" Then
Set idx = tdf.CreateIndex(strIdxName)
With idx
.Fields.Append .CreateField(strFldName)
End With
tdf.Indexes.Append idx
tdf.Indexes.Refresh
End If
End Sub
I always use the SQL-DDL-procedures to modify the tables of my backends because it is simple, fast and "small". Have a look at the MS Knowledgebase for details.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.