0

I got an error on update on SQL statement in access VBA. Here is the code:

Dim id As Integer, docNo As String, pNo As String id = Me.txtID.Value pNo = Me.txtPENo.Value docNo = Me.txtdocNo.Value db.Execute ("UPDATE tblPE SET (PENo='" & pNo & "',DocNo='" & docNo & "') WHERE ID=" & id & ";") 
1
  • Remove the SET parentheses. Commented Jul 6, 2020 at 10:12

2 Answers 2

1

For readability and maintainiability, consider parameterization via QueryDefs and avoid concatenating and punctuating VBA variables within SQL:

Dim db As Database, qdef As QueryDef Dim sql As String ' PREPARED STATEMENT (NO DATA) sql = "PARAMETERS [prm_pNo] TEXT, [prm_docNo] TEXT, [prm_id] INTEGER;" _ & "UPDATE tblPE SET PENo=[prm_pNo], DocNo=[prm_docNo] WHERE ID=[prm_id];" Set db = CurrentDb Set qdef = db.CreateQueryDef("", sql) ' BIND PARAMS qdef!prm_id = Me.txtID.Value qdef!prm_pNo = Me.txtPENo.Value qdef!prm_docNo = Me.txtdocNo.Value ' EXECUTE ACTION qdef.Execute ' RELEASE RESOURCES Set qdef = Nothing: Set db = Nothing 
Sign up to request clarification or add additional context in comments.

Comments

0

The problem is with the extra brackets in the SQL statement. Instead, try:

 db.Execute ("UPDATE tblPE SET PENo='" & pNo & "',DocNo='" & docNo & "' WHERE ID=" & id & ";") 

Regards,

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.