Microsoft Access,vbYesNo无法获取保存记录

时间:2017-12-03 00:15:33

标签: vba ms-access-2010

关于Access的问题,我在保存记录按钮上创建了一个vbYesNo,询问我是否是新记录,如果是,则保存为新记录,否则我需要它来更新现有记录

Private Sub btnSaveDetails_Click()

    Dim Response As Integer

    Response = MsgBox("Do you wish to create a new record?", vbYesNo, "Continue?")


    If IsNull(txtLocation) Then
        MsgBox "Please Enter Location Details"
    Else
        If Response = vbYes Then
            DoCmd.RunCommand acCmdSaveRecord
            DoCmd.GoToRecord , , acNewRec
            Me.Refresh
            Me.cboSelectLocation = ""
            txtLocation.SetFocus
        Else
            DoCmd.RunCommand acCmdUndo
        End If
    End If
End Sub

问题基本上是在Save按钮上询问它是否是新记录,如果是vbNo我需要它来更新当前记录。

1 个答案:

答案 0 :(得分:0)

与你的方法不同,但这就是我的方法:

If CloseResponse = vbNo Then
    Exit Sub
Else

CurrentDb.Execute "UPDATE tbl_Suggestions_Historic SET [Status] = 'Closed By User', [ReasonClosed] = '" & ClosedWhy & "' WHERE ID = '" & ID & "'"
相关问题