2017-12-18 3 views
-1
CurrentDb.Execute "UPDATE Transaction SET receipt_id=" & txtreceipt_id & ", tdate=" & txttdate & ",total_cost=" & txttotal_cost & ",total_disc=" & txttotal_disc & " WHERE receipt_id=" & txtreceipt_id & " " 

Ich bekomme eine Laufzeit 3144 Syntaxfehler. Kann den Fehler nicht finden.Laufzeitfehler 3144 von UPDATE-Anweisung

enter image description here

+0

Können Sie die zeigen, vollständiger Syntaxfehler? –

+0

Benötigen Sie zusätzliche Angebote? Starten Sie mit CurrentDb.Execute "UPDATE Transaction SET receipt_id =" & txtreceipt_id und fügen Sie die anderen Felder einzeln hinzu. –

Antwort

0

Betrachten wir ein parameterized query mit MS Access' mit QueryDefs, um die Datentypen Ihrer binded-Werte genau anzugeben und Verkettung und Quote-Wrapping zu vermeiden, wodurch Code schwer zu pflegen ist. Passen Sie die folgenden Typen nach Bedarf in PARAMETERS (in Access SQL konform) an.

SQL(speichern als MS Access gespeicherte Abfrage nur einmal)

PARAMETERS [txtreceipt_id_PARAM] LONG, [txttdate_PARAM] DATE, 
      [txttotal_cost_PARAM] DOUBLE, [txttotal_disc_PARAM] DOUBLE; 
UPDATE [Transaction] 
SET receipt_id = [txtreceipt_id_PARAM], 
    tdate = [txttdate_PARAM], 
    total_cost = [txttotal_cost_PARAM], 
    total_disc = [txttotal_disc_PARAM] 
WHERE receipt_id = [txtreceipt_id_PARAM]; 

VBA(dynamisch Werte binden Platzhalter für den Parameter)

Dim qdef as QueryDef 

Set qdef = CurrentDb.QueryDefs("mySavedQuery") 

qdef![txtreceipt_id_PARAM] = txtreceipt_id 
qdef![txttdate_PARAM] = txttdate 
qdef![txttotal_cost_PARAM] = txttotal_cost 
qdef![txttotal_disc_PARAM] = txttotal_disc 

qdef.Execute dbFailOnError 

Set qdef = Nothing 
+0

Vielen Dank. Wusste nicht über die Abfrage defs. –

0

sieht so wie die Syntax ein wenig aus ist ... Es könnte den Code in Stücke aufzuteilen helfen ... Ich war nicht in der Lage, diese Lösung zu testen, sondern versuchen, diese (Es hängt alles auf den Datentyp):

CurrentDb.Execute "UPDATE Transaction " & _ 
" SET receipt_id = '" & txtreceipt_id & "'" & _ 
", tdate = " & txttdate & "" & _ 
", total_cost = " & txttotal_cost & "" & _ 
", total_disc = " & txttotal_disc & "" & _ 
" WHERE receipt_id = '" & txtreceipt_id & "'" 

Wenn txreceipt_id eine Zahl dann versuchen:

CurrentDb.Execute "UPDATE Transaction " & _ 
" SET receipt_id = " & txtreceipt_id & "" & _ 
", tdate = " & txttdate & "" & _ 
", total_cost = " & txttotal_cost & "" & _ 
", total_disc = " & txttotal_disc & "" & _ 
" WHERE receipt_id = " & txtreceipt_id & "" 
+0

Es ist wahrscheinlich txtdate, das einfache Anführungszeichen benötigt. Auch "&" "scheint sinnlos. – itsLex