Visual Basic Access-从文本框中记录信息



我正在尝试创建一个允许您注册用户的表单。我查阅了教程,但似乎都不起作用。这是我目前使用的代码:

CurrentDb.Execute "INSERT INTO tblUser(User ID, Fullname, Username, Password, Security) " _
& VALUES & " (" & Me.ID & ",'" & Me.Fullname & "','" & Me.Uname & "','" & _
Me.uPass & "','" & Me.Pri & "')"

当我运行代码时,我得到:

运行时错误"3134":INSERT INTO语句中存在语法错误。

两个错误:

  1. 您的某个字段中有空间。如果有空间,请使用括号或者如果你使用保留字。

  2. VALUES必须包含在字符串中,而不是作为变量。

校正:

CurrentDb.Execute "INSERT INTO tblUser([User ID], Fullname, Username, Password, Security) " & _
"VALUES (" & Me.ID & ",'" & Me.Fullname & "','" & Me.Uname & "','" & _
Me.uPass & "','" & Me.Pri & "')"

根据我的评论,请尝试以下内容:

CurrentDb.Execute "INSERT INTO tblUser(User ID, Fullname, Username, Password, Security) " _
& "VALUES(" & Me.ID & ",'" & Me.Fullname & "','" & Me.Uname & "','" & _
Me.uPass & "','" & Me.Pri & "')"

密码是一个保留字,因此:

CurrentDb.Execute "INSERT INTO tblUser(User ID, Fullname, Username, [Password], Security) " _

最新更新