0

I am new to MS-ACCESS and SQL. I am trying to update a field in a linked SQL table but I keep getting

3075 Syntax Error. 

PartData is the linked table What am I missing?

Private Sub REVISE_Click()
On Error GoTo REVISE_Click_Err
'
'***** Define Variables *****
Dim strSQL1 As String 
Dim strSQL2 As String
'
'***** Set Default Values *****
strSQL1 = "Delete * From Inspector"
strSQL2 = "UPDATE PartData SET SpecialNote = " & SpecNotes & " WHERE PartNo= '" & PartNumberSearch & "'"
'
'***** Clear Inspector Values ***** 
CurrentDb.Execute strSQL1, dbFailOnError 
CurrentDb.Execute strSQL2, dbFailOnError
'
DoCmd.Quit acPrompt 
'
REVISE_Click_Exit:
   Exit Sub 
'
REVISE_Click_Err:
   MsgBox Error$ 
   Resume EXIT_Click_Exit
'
End Sub 

2 Answers 2

1

I guess you're building query from VBA. You then have a quote issue, since SpecNotes is obviously a string. Try this:

strSQL2 = "UPDATE PartData SET SpecialNote = '" & SpecNotes & "' WHERE PartNo= '" & PartNumberSearch & "'"

I also think that you could improve your query by using parameters, but that could be another question, and you should then show a bit more of your code, so we can see the context. Note that, without parameters, strSQL2 could produce unexpected results if SpecNote contains quotes.

Sign up to request clarification or add additional context in comments.

2 Comments

Private Sub REVISE_Click() On Error GoTo REVISE_Click_Err '***** Define Variables ***** Dim strSQL1 As String Dim strSQL2 As String ' '***** Set Default Values ***** strSQL1 = "Delete * From Inspector" strSQL2 = "UPDATE PartData SET SpecialNote = " & SpecNotes & " WHERE PartNo= '" & PartNumberSearch & "'" ' '***** Clear Inspector Values ***** CurrentDb.Execute strSQL1, dbFailOnError CurrentDb.Execute strSQL2, dbFailOnError ' DoCmd.Quit acPrompt REVISE_Click_Exit: Exit Sub REVISE_Click_Err: MsgBox Error$ Resume EXIT_Click_Exit End Sub
@Tombo Can't you edit your question and include your code in it ?
0

Patrick, Sorry, still learning. Please see code below.

Private Sub REVISE_Click()
On Error GoTo REVISE_Click_Err
'
'***** Define Variables *****
Dim strSQL1 As String 
Dim strSQL2 As String
'
'***** Set Default Values *****
strSQL1 = "Delete * From Inspector"
strSQL2 = "UPDATE PartData SET SpecialNote = " & SpecNotes & " WHERE PartNo= '" & PartNumberSearch & "'"
'
'***** Clear Inspector Values ***** 
CurrentDb.Execute strSQL1, dbFailOnError 
CurrentDb.Execute strSQL2, dbFailOnError
'
DoCmd.Quit acPrompt 
'
REVISE_Click_Exit:
   Exit Sub 
'
REVISE_Click_Err:
   MsgBox Error$ 
   Resume EXIT_Click_Exit
'
End Sub 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.