【问题标题】:Runtime error 3075 missing operator运行时错误 3075 缺少运算符
【发布时间】:2015-09-10 19:06:27
【问题描述】:

当我使用 ms access 2007 时,它运行良好。我切换到 ms access 2010,现在它不起作用。

 DoCmd.RunSQL ("INSERT INTO Pending_Orders (Customer, ItemNumber, Description,   Qty, [Order #], Temp, ShipDate) VALUES (" & _
  "'" & Replace(rst!Customer, "'", "''") & "','" & rst![Item #] & "','" & rst!Description & "'," & rst!Qty & ",'" & rst![Order #] & "'," & NextTemp & ",#" & rst![Ship Date] & "#)")

我现在收到此错误。

可能是什么?

【问题讨论】:

  • 通常错误 #3075 的消息包含更多信息。您是否包含错误消息的全文?

标签: vba ms-access ms-access-2010


【解决方案1】:

我建议您将上述代码中的单引号替换为双引号,这是 Paul O'Connor 等名称的常见问题。还可以通过 DoCmd.RunSQL 使用 CurrentDb.Execute。使用 currentBD 时,您可以抑制烦人的消息并查看更多信息。最后,始终使用字符串来获取 SQL 查询,这样调试会容易得多。

试试下面的,

strSQL = "INSERT INTO Pending_Orders (Customer, ItemNumber, Description, Qty, [Order #], " & _
         "Temp, ShipDate) VALUES (" & Chr(34) & rst!Customer & Chr(34) & _
         ", " & Chr(34) & rst![Item #] & Chr(34) & _
         ", " & Chr(34) & rst!Description & Chr(34) & _
         ", " & rst![Qty] & ", " & Chr(34) & rst![Order #] & Chr(34) & _
         ", " & NextTemp & ", " & Format(rst![Ship Date], "\#mm\/dd\/yyyy\#") & ")

CurrentDB.Execute strSQL 

【讨论】:

  • Do While Not rst.EOF 'Get PendigOrder Used Available = GetAvailable(rst![Item #]) If Available = 0 Then NextTemp = rst!Qty * -1 'ElseIf Available >= rst!Qty Then Else NextTemp = Available - rst!Qty 'ava = NextTemp End If DoCmd.RunSQL ("INSERT INTO Pending_Orders (Customer, ItemNumber, Description, Qty, [Order #], Temp, ShipDate) VALUES (" & _"'" & Replace(rst!Customer, "'", "''") & "','" & rst![Item #] & "','" & rst!Description & "'," & rst!Qty & ", '" & rst![Order #] & "'," & NextTemp & ",#" & rst![Ship Date] & "#)")
  • 请编辑您的原始帖子。 cmets 不能很好地编写代码。
【解决方案2】:

除了 Paul Francis 的回答之外,我还提供了 EscapeDBstring 函数,它通过转义嵌入的引号来解决 "Paul O'Connor" 中的嵌入引号问题:

' dbEscapeString -- escape the single quote in a string that will be included in
'                   an SQL statement. The single quote is the database/SQL string delimiter.
Public Function dbEscapeString(ByVal s)
Dim i
    i = 1
    While (i <= Len(s))
        If (Mid(s, i, 1) = "'") Then
            'If (Mid(s, i + 1, 1) = "'") Then   ' this would consider two single quotes to be escaped already
            '    i = i + 1
            'Else
                s = Mid(s, 1, i) + Mid(s, i)
                i = i + 1
            'End If
        End If
        i = i + 1
    Wend
    dbEscapeString = s
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多