2015-06-24 84 views
3

當我使用ms access 2007時,它完美地工作。我打開ms訪問2010年,現在它不起作用。運行時錯誤3075缺少運算符

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] & "#)") 

我現在正在收到此錯誤。

它可能是什麼?

+1

錯誤#3075的消息通常包含更多信息。你是否包含錯誤信息的全文? – HansUp

回答

0

我建議你用上面的代碼中的單引號替換成雙引號,這是Paul O'Connor這樣的名字常見的問題。也可以通過DoCmd.RunSQL使用CurrentDb.Execute。由於使用currentBD,您可以抑制令人討厭的消息並查看更多信息。最後,總是使用String來獲取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 
+0

待辦事項雖然不是rst.EOF '獲取PendigOrder使用 服務= GetAvailable(RST![編號]) (如果可用)= 0,那麼 NextTemp =第一個!數量* -1 ' elseif的可用> =第一個!數量然後 否則 NextTemp =可用 - !RST數量 「AVA = NextTemp 結束如果 DoCmd.RunSQL( 「INSERT INTO Pending_Orders(客戶,ItemNumber,描述,數量,[訂單號],溫度,並按ShipDate)VALUES(」 &_」 ''&Replace(rst!Customer,「'」,「''」)&「','」&rst![Item#]&「','」&rst!描述&「',」&rst!Qty &「,'」&rst![Order#]&「',」&NextTemp&「,#」&rst![發貨日期]&「#)」) –

+0

同樣的問題。我會寄給你我的代碼 –

+0

請編輯你的原始文章。代碼doe鼻涕好評與評論。 – PaulFrancis

0

除了保羅弗朗西斯回答,我提供EscapeDBstring功能,通過轉義嵌入的引號解決了在「保奧康納」嵌入的引號的問題:

' 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 
相關問題