识别数据条目而不更改ID

时间:2017-02-24 15:48:36

标签: access-vba ms-access-2010

我正在尝试创建更新表单。它应该从表单上的文本框中获取值,并使用ID的自动编号作为标识符更新该注册表。它说我不能编辑ID,即使我不认为我。

Private Sub edit_Click()

'Will edit the currently selected record
CurrentDb.Execute "UPDATE DataInput " & _
    " SET ID=" & Me.txtID & _
    ", [Date]='" & Me.Date & "'" & _
    ", [Time Up]='" & Me.txttimeup & "'" & _
    ", [Notes]='" & Me.CboNotes & "'" & _
    ", [Time Down]='" & Me.txtTimeDown & "'" & _
    " WHERE ID=" & Me.txtID.Tag

        Me.txtID.Tag = ""

'refresh data on form
DataInput_subform.Form.Requery

'Disable Update Button
Me.edit.Enabled = False

'Enable Edit Button
Me.cmdEdit.Enabled = True

'Clear texts
cmdClear_Click

1 个答案:

答案 0 :(得分:0)

尝试以更易读的方式格式化代码并添加类似

的调试
Dim sSql As String

sSql = "UPDATE DataInput SET [Date]=#" & Format(Me.Date,"mm/dd/yyyy") & "#, " 
sSql = sSql & "[Time Up] = '" & Me.txttimeup & "', [Notes] ='" & Me.CboNotes & "', " 
sSql = sSql & "[Time Down] = '" & Me.txtTimeDown & "' "
sSql = sSql & "WHERE ID = " & Me.txtID & " ;" 

Debug.Print sSql
CurrentDb.Execute sSql