Access 2013插入/更新

时间:2015-08-13 12:26:52

标签: insert updates ms-access-2013

我有一个表单来添加用户。

我可以添加,删除表中的行,但如果用户已经存在,我会假装更新。

我的目标是按子表单中的行进行编辑。 但是每次按下更新都会给我一个错误。

  

运行时错误' 3075'查询表达式中的语法错误运算符。

我的行动代码就是这个

Private Sub cmdAdd_Click()
    'quando se carrega em Adicionar há 2 opcoes
    '1-Insert
    '2-Update
    If Me.txtuserid.Tag & "" = "" Then

        '1
        CurrentDb.Execute "INSERT INTO user(userid, username, userfunction, usercc) " & _
                " VALUES(" & Me.txtuserid & ",'" & Me.txtusername & "','" & Me.txtuserfun & "','" & Me.txtusercc & "')"
     Else
     '2
     CurrentDb.Execute "UPDATE user " & _
            " SET userid=" & Me.txtuserid & _
            ", username=" & Me.txtusername & "'" & _
            ", userfunction =" & Me.txtuserfun & "'" & _
            ", usercc =" & Me.txtusercc & "'" & _
            " WHERE userid =" & Me.txtuserid.Tag
      End If
    'clear fields
    cmdClear_Click
    'refresh
    SubForm1.Form.Requery
End Sub 

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您是否错过了更新声明中的';

CurrentDb.Execute "UPDATE user " & _
        " SET userid=" & Me.txtuserid & _
        ", username='" & Me.txtusername & "'" & _
        ", userfunction ='" & Me.txtuserfun & "'" & _
        ", usercc ='" & Me.txtusercc & "'" & _
        " WHERE userid =" & Me.txtuserid.Tag