将DAO属性添加到数据库

时间:2014-05-22 07:02:46

标签: vba access-vba dao

我正在尝试通过以下代码创建属性:

Public Sub refresh()
    Dim prp As DAO.Property
    Set prp = CurrentDb.CreateProperty("LastRefreshedDate", dbDate, Date)
End Sub

我在构建过程中创建了以下内容来存储LastRefreshedDate,然后通过标题标签在用户表单上显示此内容,但是,该属性未显示。

' Store refresh date
CurrentDb.Properties("LastRefreshedDate") = Date
lblRefresh.Caption = "Last Refreshed: " & Format(CurrentDb.Properties("LastRefreshedDate"), " dd mmm yyyy") 

1 个答案:

答案 0 :(得分:1)

"我忘了将财产追加到CurrentDb。"

正确的代码:

Public Sub refresh()
    Dim prp As DAO.Property
    Set prp = CurrentDb.CreateProperty("LastRefreshedDate", dbDate, Date)
    ' property has to be appended after it is created.
    Currentdb.Properties.Append prp
End Sub

MSDN documentation on the DAO.Properties collection.