Here is a an example of adding a field to an existing table using DAO
Public Function AddMyField()
Dim dbs As DAO.Database
Dim tbl As DAO.TableDef
Dim fld As DAO.Field
'set a reference to the database you want to change
Set dbs = CurrentDB
'you could use DBEngine.OpenDatabase(PathToFile) to connect to a
'database other than the one you are running your code in.
'set a reference to the table you want to change
Set tbl = dbs.TableDefs("MyTable")
'create a new field object
Set fld = tbl.CreateField("MyNewField", dbLong)
'dbLong = Long Integer
'dbText = Text
'dbMemo = Memo
'dbDate = Date/Time
' look up DataTypeEnum in the Object Browser for a complete list
'add the field to the table
tbl.Fields.Append fld
'now change other properties of your new field
fld.Required = True
'clean up
Set fld = Nothing
Set tbl = Nothing
Set dbs = Nothing
End Function
I 've got similar problem with Carlee. I'm using a crosstab query that miss one field because there is no data in it that's why I have to add it from VBA.
TIA,
Djoezz
I 've got similar problem with Carlee. I'm using a crosstab query that miss one field because there is no data in it that's why I have to add it from VBA.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.