我在update语句中遇到语法错误。运行时错误:3144我使用以下代码

时间:2017-05-12 04:58:43

标签: ms-access

Private Sub cmdAdd_Click()
    'when we Click on button Add there are two options
    '1. for insert
    '2. for update
    If Me.txtdate.Tag & "" = "" Then
            'this is for insert new
            'add data to table
                CurrentDb.Execute "INSERT INTO BphCore1(DateOfTesting, TestingAt, VoltageLevel, PolarityCheck, AppliedVoltageInPrimary, AppliedVoltageInSecondary, MeasurmentUnitIR, MinimumValue, PrimaryToEarth, PrimaryToSecondary,SecondaryToEarth, MeasurmentUnitWR, WRSecondaryValues, 20OfInjectedValue, 20OfMeasurmentValue, 40OfInjectedValue, 40OfMeasurmentValue, 60OfInjectedValue, 60OfMeasurmentValue, 80OfInjectedValue, 80OfMeasurmentValue, 100OfInjectedValue, 100OfMeasurmentValue, KneePointVoltage, MagnetizingCurrent) " & _
                        " VALUES('" & Me.txtdate & "','" & Me.cbotest & "','" & Me.cbovl & "','" & Me.cbopc & "','" & Me.cboavp & "','" & Me.cboavs & "','" & Me.cbomuir & "','" & _
                        Me.txtMV & "','" & Me.txtpe & "','" & Me.txtps & "','" & Me.txtse & "','" & Me.cbomuwr & "','" & Me.txtwrsv & "','" & Me.txti20 & "','" & Me.txtm20 & "','" & Me.txti40 & "','" & Me.txtm40 & "','" & Me.txti60 & "','" & Me.txtm60 & "','" & Me.txti80 & "','" & Me.txtm80 & "','" & Me.txti100 & "','" & Me.txtm100 & "','" & Me.txtkpv & "','" & Me.txtmc & "')"
     Else
            'otherwise (Tag of txtdate store the DateOfTesting of BphCore1 to be modified)
            CurrentDb.Execute " UPDATE BphCore1 " & _
                        " SET DateOfTesting=" & Me.txtdate & _
                        ", TestingAt='" & Me.cbotest & "'" & _
                        ", VoltageLevel='" & Me.cbovl & "'" & _
                        ", PolarityCheck='" & Me.cbopc & "'" & _
                        ", AppliedVoltageInPrimary='" & Me.cboavp & "'" & _
                        ", AppliedVoltageInSecondary='" & Me.cboavs & "'" & _
                        ", MeasurmentUnitIR='" & Me.cbomuir & "'" & _
                        ", MinimumValue='" & Me.txtMV & "'" & _
                        ", PrimaryToEarth='" & Me.txtpe & "'" & _
                        ", PrimaryToSecondary='" & Me.txtps & "'" & _
                        ", SecondaryToEarth='" & Me.txtse & "'" & _
                        ", MeasurmentUnitWR='" & Me.cbomuwr & "'" & _
                        ", WRSecondaryValues='" & Me.txtwrsv & "'" & _
                        ", 20OfInjectedValue='" & Me.txti20 & "'" & _
                        ", 20OfMeasurmentValue='" & Me.txtm20 & "'" & _
                        ", 40OfInjectedValue='" & Me.txti40 & "'" & _
                        ", 40OfMeasurmentValue='" & Me.txtm40 & "'" & _
                        ", 60OfInjectedValue='" & Me.txti60 & "'" & _
                        ", 60OfMeasurmentValue='" & Me.txtm60 & "'" & _
                        ", 80OfInjectedValue='" & Me.txti80 & "'" & _
                        ", 80OfMeasurmentValue='" & Me.txtm80 & "'" & _
                        ", 100OfInjectedValue='" & Me.txti100 & "'" & _
                        ", 100OfMeasurmentValue='" & Me.txtm100 & "'" & ", KneePointVoltage='" & Me.txtkpv & "'" & ", MagnetizingCurrent='" & Me.txtmc & "'" & _
                        " WHERE DateOfTesting=" & Me.txtdate.Tag
          End If

 'clear form
     cmdclean_Click
 'refresh data in the list on form
    BphCore1subfrm.Form.Requery
End Sub

1 个答案:

答案 0 :(得分:0)

日期/时间字段的参数使用#delimiter,文本字段的参数使用撇号分隔符,数字字段的参数不需要分隔符。

" VALUES(#" & Me.txtdate & "#,'"

" SET DateOfTesting=#" & Me.txtdate & "#" & _

" WHERE DateOfTesting=#" & Me.txtdate.Tag & "#"