ADD/UPDATE 按钮语法错误
ADD/UPDATE BUTTON syntax error
我目前正在 MS Access 2013 中编写我的 Add/Update 按钮,但由于某些奇怪的原因,我在尝试使其工作时遇到了问题,它告诉我的是我有一个 'syntax error on the UPDATE statement'... 这里是我的整体代码:
Private Sub cmdAdd_Click()
'In the button add we have two options
'1. Insert
'2. Update
If Me.txtID.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO tblClients ( ClientID, ClientName, Gender, " & _
"City, [Address (Fisical)], [Cellphone/Telephone] ) " & _
"SELECT " & Me.txtID & ",'" & Me.txtName & "','" & Me.cboGender & "', '" & Me.cboCity & "','" & Me.txtAddress & "','" & Me.txtCellphone & "'"
Else
'Otherwise the data will be updated
CurrentDb.Execute "UPDATE tblClients" & _
"SET ClientID =" & Me.txtID & _
", ClientName='" & Me.txtName & "'" & _
", Gender='" & Me.cboGender & "'" & _
", City='" & Me.cboCity & "'" & _
", Cellphone/Telephone='" & Me.txtCellphone & "'" & _
", Address (Fisical) ='" & Me.txtAddress & "'" & _
"WHERE ClientID =" & Me.txtID.Tag
End If
cmdClear_Click
tblClients_subform.Form.Requery
End Sub
请提供帮助
看起来很接近,这样想是因为我知道当它发生时我会感到沮丧。如果错误说语法错误,那不是说谎,而且对我来说,这往往是见树不见林。您缺少一些空格:-
CurrentDb.Execute "UPDATE [tblClients]" & _
" SET [ClientID] =" & Me.txtID & _
", [ClientName]='" & Me.txtName & "'" & _
", [Gender]='" & Me.cboGender & "'" & _
", [City]='" & Me.cboCity & "'" & _
", [Cellphone/Telephone]='" & Me.txtCellphone & "'" & _
", [Address (Fisical)] ='" & Me.txtAddress & "'" & _
" WHERE [ClientID] =" & Me.txtID.Tag
- Space 在
SET ClientID...
之前
- Space 在
WHERE ClientID
之前
- 括号列和 table 名称
也是我为此学到的一个技巧:-
- 打开一个新查询并查看 SQL
- 将要执行的字符串粘贴进去
- 运行它
您可以获得有关问题所在的更多信息。
我目前正在 MS Access 2013 中编写我的 Add/Update 按钮,但由于某些奇怪的原因,我在尝试使其工作时遇到了问题,它告诉我的是我有一个 'syntax error on the UPDATE statement'... 这里是我的整体代码:
Private Sub cmdAdd_Click()
'In the button add we have two options
'1. Insert
'2. Update
If Me.txtID.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO tblClients ( ClientID, ClientName, Gender, " & _
"City, [Address (Fisical)], [Cellphone/Telephone] ) " & _
"SELECT " & Me.txtID & ",'" & Me.txtName & "','" & Me.cboGender & "', '" & Me.cboCity & "','" & Me.txtAddress & "','" & Me.txtCellphone & "'"
Else
'Otherwise the data will be updated
CurrentDb.Execute "UPDATE tblClients" & _
"SET ClientID =" & Me.txtID & _
", ClientName='" & Me.txtName & "'" & _
", Gender='" & Me.cboGender & "'" & _
", City='" & Me.cboCity & "'" & _
", Cellphone/Telephone='" & Me.txtCellphone & "'" & _
", Address (Fisical) ='" & Me.txtAddress & "'" & _
"WHERE ClientID =" & Me.txtID.Tag
End If
cmdClear_Click
tblClients_subform.Form.Requery
End Sub
请提供帮助
看起来很接近,这样想是因为我知道当它发生时我会感到沮丧。如果错误说语法错误,那不是说谎,而且对我来说,这往往是见树不见林。您缺少一些空格:-
CurrentDb.Execute "UPDATE [tblClients]" & _
" SET [ClientID] =" & Me.txtID & _
", [ClientName]='" & Me.txtName & "'" & _
", [Gender]='" & Me.cboGender & "'" & _
", [City]='" & Me.cboCity & "'" & _
", [Cellphone/Telephone]='" & Me.txtCellphone & "'" & _
", [Address (Fisical)] ='" & Me.txtAddress & "'" & _
" WHERE [ClientID] =" & Me.txtID.Tag
- Space 在
SET ClientID...
之前
- Space 在
WHERE ClientID
之前
- 括号列和 table 名称
也是我为此学到的一个技巧:-
- 打开一个新查询并查看 SQL
- 将要执行的字符串粘贴进去
- 运行它
您可以获得有关问题所在的更多信息。