我目前在MS Access 2013中编写了我的添加/更新按钮,但由于一些奇怪的原因,我无法尝试使其工作,它告诉我的是我在UPDATE语句中有'语法错误'...这里是我的整体代码:
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
请提供帮助
答案 0 :(得分:0)
看起来很近,以这种方式想起来,因为我知道它会在发生时让我感到沮丧。如果错误说的是语法错误,它不会说谎,而且对我来说往往不能看到木头的树木。你错过了几个空格: -
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
SET ClientID...
WHERE ClientID
这也是我学到的一个技巧: -
您可以获得有关问题所在位置的更多信息。