【问题标题】:Deleting record on Continuous form in MS Access using acCmdDeleteRecord使用 acCmdDeleteRecord 在 MS Access 中删除连续表单上的记录
【发布时间】:2016-09-01 06:35:27
【问题描述】:

我的表单只有 2 个字段和一个按钮。

设计视图

'

表单视图

下面是删除按钮的代码。

Private Sub cmdDelete_Click()
     DoCmd.RunCommand acCmdDeleteRecord
     Debug.Print "IDWeb - " & Me.IDWeb
     'Here I Execute a Web API to Delete Data based on Me.IDWeb
End Sub

问题 - Web API 没有得到 Me.IDWeb Value 。有时IDWeb 被正确捕获,有时不是。

Edit1 :我尝试了下面的代码。但是问题依然存在。

我猜用户在删除当前记录时可能在另一条记录上。因此问题。但该记录当前已在 MS Access 中删除。唯一的问题是 Me.IDWeb 未被正确捕获,因此我的 Web API 失败了。

Private Sub cmdDelete_Click()
    Me.WebType.SetFocus
    If Me.IDWeb = "" Or Me.IDWeb = vbNull Or Me.IDWeb = vbNullString Then
        MsgBox "No Record Selected"
    Else
        DoCmd.RunCommand acCmdSelectRecord
        DoCmd.RunCommand acCmdDeleteRecord
        Debug.Print "IDWeb - " & Me.IDWeb
        'Here I execute my Web API to Delete based on Me.IDWeb
    End If
End Sub

【问题讨论】:

  • 我建议你首先获取Me.IDWeb(将其存储在变量中),然后运行acCmdDeleteRecord
  • @Andre 精湛。问题解决了。谢谢

标签: ms-access vba delete-row


【解决方案1】:

解决方案是首先获取 Me.IDWeb 并将其存储在一个变量中,

然后运行acCmdDeleteRecord

【讨论】:

    【解决方案2】:

    就我个人而言,我不使用 DoCmd。您正在尝试获取已删除记录的 IdWeb。 假设您的 IDWeb 是一个数字(如果不使用适当的数据类型),以下应该可以工作

    Dim lngIdWeb as long
    lngIdWeb = nz(Me.IdWeb, 0)
    If lngIdWeb > 0 Then
    Me.RecordsetClone.FindFirst "IdWeb = " & lngIdWeb
    If Not Me.RecordsetClone.NoMatch Then
    Me.RecordsetClone.Delete
    End If
    Debug.Print "IdWeb - " & lngIdWeb
    End If
    

    【讨论】:

    • 由@Andre 方法解决(在问题的评论中提到)。感谢您的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-12
    相关资源
    最近更新 更多