0

我有一个表格和子表格。我试图允许使用按钮在子表单中进行更新。但是我的代码给了我。

KEY_ID 是文本,另外两个是数字类型。

“查询表达式“5”中的语法错误,ROOM=5。DRAWER=55(这是我尝试将其更改为的新值)WHERE KEY_ID=5'。

这是我的表格的图像:http: //jumpshare.com/b/17A7Pr

这就是我正在尝试的:

Private Sub cmdAdd_Click()
If Me.keyID.Tag & "" = "" Then
    CurrentDb.Execute "INSERT INTO KEYS(KEY_ID, ROOM, DRAWER)" & _
        " VALUES('" & Me.keyID & "'," & Me.roomID & "," & Me.drawerID & ")"
          subKey.Form.Requery
Else
    CurrentDb.Execute "UPDATE KEYS " & _
    " SET KEY_ID=" & Chr(39) & keyID & Chr(39) & _
    ", ROOM=" & Me.roomID & _
    ", DRAWER=" & Me.drawerID & _
    " WHERE KEY_ID=" & Me.keyID.Tag
    Debug.Print KEY_ID
End If

解决方案:

CurrentDb.Execute "UPDATE KEYS " & _
" SET KEY_ID=" & Me.keyID & _
", ROOM=" & Me.roomID & _
", DRAWER=" & Me.drawerID & _
" WHERE KEY_ID=" & Chr(39) & keyID.Tag & Chr(39)
4

2 回答 2

1

解决方案:

CurrentDb.Execute "UPDATE KEYS " & _
" SET KEY_ID=" & Me.keyID & _
", ROOM=" & Me.roomID & _
", DRAWER=" & Me.drawerID & _
" WHERE KEY_ID=" & Chr(39) & keyID.Tag & Chr(39)
于 2013-01-11T03:19:13.117 回答
0

尝试没有 Chr(39) 的代码。这应该可以。

Private Sub cmdAdd_Click()
If Me.keyID.Tag & "" = "" Then
    CurrentDb.Execute "INSERT INTO KEYS(KEY_ID, ROOM, DRAWER)" & _
        " VALUES('" & Me.keyID & "'," & Me.roomID & "," & Me.drawerID & ")"
          subKey.Form.Requery
Else
    CurrentDb.Execute "UPDATE KEYS " & _
    " SET KEY_ID=" &  keyID  & _
    ", ROOM=" & Me.roomID & _
    ", DRAWER=" & Me.drawerID & _
    " WHERE KEY_ID=" & Me.keyID.Tag
    Debug.Print KEY_ID
End If
于 2013-01-11T03:18:55.147 回答