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_Click()
On Error GoTo ErrAddNewField_Click
Dim db As DAO.Database
Dim fld As DAO.Field
Dim tdf As DAO.TableDef
Set db = Application.CurrentDb
Set tdf = db.TableDefs("tblTestCode")
Set fld = tdf.CreateField("MyNewField1", dbText, 150)
With fld
.AllowZeroLength = 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_ErrAddNewField_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