I am writing some vba to create a new field if it is not already there.
Code follows.
The code I have so far, creates the new field in the table and sets the
AllowZeroLength property = true.
'Start code
Private Sub AddNewField_Cli ck()
On Error GoTo ErrAddNewField_ Click
Dim db As DAO.Database
Dim fld As DAO.Field
Dim tdf As DAO.TableDef
Set db = Application.Cur rentDb
Set tdf = db.TableDefs("t blTestCode")
Set fld = tdf.CreateField ("MyNewField 1", dbText, 150)
With fld
.AllowZeroLengt h = True
End With
With tdf.Fields
.Append fld
.Refresh
End With
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing
Exit Sub
ErrAddNewField_ Click:
MsgBox Err.Description
Resume Exit_ErrAddNewF ield_Click
End Sub
'End code
I have two problems.
1. How do I create this new field ONLY if it does not already exist.
2. This code defaults to Unicode Compression = No for a text field and I
would like it to be Yes. How do I do this?
dixie