【问题标题】:Retrieving the new contents of a control in its On Change event handler在其 On Change 事件处理程序中检索控件的新内容
【发布时间】:2013-12-13 10:12:24
【问题描述】:
Public Function EditUpdate()
Dim rstEditAddress As DAO.Recordset
Dim Svalue, EditedAddressLine1 As Variant

Svalue = Me.lstBoxCompanyName.Value

EditAddressValue = "SELECT * FROM Companies WHERE CompanyID =  " & Svalue
Set rstEditAddress = CurrentDb.OpenRecordset(EditAddressValue)

EditedAddressLine1 = Me.txtbxAddressLine1.Value

With rstEditAddress
 .Edit
    .Fields("AddressLine1") = EditedAddressLine1
    .Fields("AddressLine2") = NewAddressLine2
    .Fields("AddressLine3") = NewAddressLine3
    .Fields("Town") = NewTown
 .Update
End With

End Function

我有一个方便地命名为txtbxAddressLine1 的文本框。使用 Access 中的On Change 事件,该事件调用此函数并应通过使用“已编辑”数据更新表中记录的过程。但是EditedAddressLine1 中的值似乎永远不会改变!它始终具有最初在表中的值。

关于为什么会发生这种情况的任何建议?

【问题讨论】:

  • 在With ... 块之前执行Debug.Print EditedAddressLine1。查看EditedAddressLine1 中存储的值是否是您期望被覆盖的实际值

标签: string vba ms-access recordset


【解决方案1】:

在控件的Change 事件处理程序中,读取其Text 而不是Value 属性以获取新数据:

EditedAddressLine1 = Me.txtbxAddressLine1.Text

【讨论】:

    猜你喜欢
    • 2015-01-21
    • 1970-01-01
    • 1970-01-01
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 2014-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多