任何人都可以帮我用下面的代码来编辑记录吗?我正在尝试编辑但是有一个语法错误,我无法解决这个问题。 请参阅下面显示的错误。 运行时错误' 3075' 查询表达式中的语法错误(缺少运算符)' TypeID ='。
Private Sub oshaadd_Click()
'On Error Resume Next
If (IsNull(Me.oshaID) Or (Me.oshaID = "") And IsNull(Me.oshatype) Or (Me.oshatype = "")) Then
MsgBox "please fill required fields!", vbInformation, "Information"
Exit Sub
End If
If Me.oshaID.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO osha(TypeID, OSHA)" & _
"VALUES ('" & Me.oshaID & "', '" & Me.oshatype & "')"
If MsgBox("Added", vbOKOnly) Then
Me.osha_subform.Form.Requery
End If
Else
CurrentDb.Execute "UPDATE osha " & _
"SET TypeID =" & Me.oshaID & _
", OSHA = '" & Me.oshatype & "'" & _
"WHERE TypeID =" & Me.oshatype.Tag
MsgBox "Updated", vbInformation, "Information"
Me.oshaadd.Caption = "Add"
Me.oshaedit.Enabled = True
End If
Me.osha_subform.Form.Requery
End Sub
Private Sub oshaedit_Click()
On Error Resume Next
If Not (Me.osha_subform.Form.Recordset.EOF And Me.osha_subform.Form.Recordset.BOF) Then
With Me.osha_subform.Form.Recordset
Me.oshaID = .Fields("TypeID")
Me.oshatype = .Fields("OSHA")
Me.oshaID.Tag = .Fields("TypeID")
Me.oshaadd.Caption = "Update"
Me.oshaedit.Enabled = False
End With
End If
End Sub
答案 0 :(得分:2)
您忘记在UPDATE SQL语句中将数据库单引号放在Me.oshaID
和Me.oshatype.Tag
周围:
CurrentDb.Execute "UPDATE osha " & _
"SET TypeID ='" & Me.oshaID & "'" & _
", OSHA = '" & Me.oshatype & "'" & _
" WHERE TypeID ='" & Me.oshatype.Tag &"';"
答案 1 :(得分:1)
CurrentDb.Execute "UPDATE osha " & _
"SET TypeID =" & Me.oshaID & _
", OSHA = '" & Me.oshatype & "'" & _
"WHERE TypeID =" & Me.oshatype.Tag
MsgBox "Updated", vbInformation, "Information"
Me.oshaadd.Caption = "Add"
Me.oshaedit.Enabled = True
在您的代码块中,您有" SET TypeID ="和" WHERE TypeID ="尝试在等号后添加一个空格,以便它读取" TypeID ="。如果这不能解决错误,请尝试在分配给TypeID的值周围添加单引号(TypeID = ' "& Me.oshaID& _&#34 ;的' 下,)