错误3075分解更新查询的长文本时

时间:2015-12-23 12:52:37

标签: sql vba ms-access-2013

“说明”字段是一个长文本字段,超过255个字符。所以我试图在更新它之前将其分解。我的错误是:

  

运行时错误'3075查询中的语法错误(缺少运算符)   表达“titlename'Set Description ='([prm_val1]&   [prm_val2] ..... [prm_val7])”。

这是我的代码:

l = Len(Me.Description)
If l Mod 255 = 0 Then   'For length exactly a multiple of 255 (255, 510, 765...)
    n = l / 255
Else
    n = Int(l / 255) + 1
End If

sp = "[prm_val1]"
If n > 1 Then 'If >255 chars tap on concatenated parameters as needed
     For p = 2 To n
         sp = sp & " & [prm_val" & p & "]"
     Next p
 End If

'UpdateDescription = "UPDATE AllProjects " & _
'"Set Description='" & sp & "'" & _
'" WHERE ID =" & Me.ID
'CurrentDb.Execute UpdateDescription

 'For p = 1 To n   'Add each 255 char piece as the parameters
     'qdf.Parameters("prm_val" & p) = Mid(varValue, (p - 1) * 255 + 1, 255)
 'Next p
 'qdf.Execute



    DoCmd.SetWarnings False
    strSQL = "UPDATE AllProjects " & _
     "Set Title='" & Me.Title & "'" & _
     "Set Description='(" & sp & ")'" & _
     ",Department='" & Me.Department & "'" & _
     ",Priority='" & Me.Priority & "'" & _
     ",Status='" & Me.Status & "'" & _
     ",[Create Date]='" & Me.CreateDate & "'" & _
     ",[% Complete]='" & Me.PerComplete & "'" & _
     ",[File Location]='" & Me.FileLocation & "'" & _
     ",[Update Notes]='" & Me.UpdateNotes & "'" & _
     ",Leader='" & Me.Leader & "'" & _
     ",[Target Date]='" & Me.TargetDate & "'" & _
     ",[Complete Date]='" & Me.CompleteDate & "'" & _
     ",Category='" & Me.Category & "'" & _
     ",Feedback='" & Me.Feedback & "'" & _
     ",[File Location 2]='" & Me.FileLocation2 & "'" & _
     ",[File Location 3]='" & Me.FileLocation3 & "'" & _
     ",[Strategic Initiatives]='" & Me.StrategicInitiatives & "'" & _
     " WHERE ID =" & Me.ID
     CurrentDb.Execute strSQL

     For p = 1 To n   'Add each 255 char piece as the parameters
             strSQL.Parameters("prm_val" & p) = Mid(varValue, (p - 1) * 255 + 1, 255)
         Next p
    DoCmd.SetWarnings True

1 个答案:

答案 0 :(得分:0)

此代码在执行后被称为,并且没有任何意义:

For p = 1 To n   'Add each 255 char piece as the parameters
    strSQL.Parameters("prm_val" & p) = Mid(varValue, (p - 1) * 255 + 1, 255)
Next p

由于strSQL没有参数。

调整此代码并在调用execute之前将其移动到代码中。

或使用您已注释掉的查询。