I use the code below to add a Text field to a table. I do NOT use a sub or function to store the code
Dim Db As DAO.Database
Dim fld As DAO.Field
Dim tdf As DAO.TableDef
Set Db = Application.CurrentDb
Set tdf = Db.TableDefs(strTableName)
' First create a field with data type = Text
Set fld = tdf.CreateField(strFieldName, dbText)
' Append the field
Set fld = Nothing
Set tdf = Nothing
Set Db = Nothing
It works the first time I use the code, but does not work the second time I include the code to add a second text field
to the same table. The instances of the code are included in the the On Open event of a form and are run as part of an update
process, depending on which version the user has. I do not get any messages. The second Text field is not added to the table.
In the second instance of the code I use different names for the Db2, tdf2, fld2.
The second Text field is added if I use an Application.Quit in between the two field addition codes.