将字段添加到Recordset

时间:2015-05-18 23:22:46

标签: vba access-vba

我一直试图让这段代码在访问中工作,只需将一个新的字段列添加到名为" Collections"的表中。但似乎Access什么都不做:

Sub CreateCalculatedField()
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field2
' get the database
Set dbs = CurrentDb()

' create the table
Set tdf = dbs.CreateTableDef("Collections")

' create the fields: first name, last name

tdf.Fields.Append tdf.CreateField("Running Total", dbText, 20)

Cleanup:
Set fld = Nothing
Set tdf = Nothing
Set dbs = Nothing
End Sub

我有什么遗失的东西吗?

1 个答案:

答案 0 :(得分:0)

是的,您需要告诉dbs您要创建表。

Dbs.TableDefs.Append tdf