0

I have the following code that I have read and made changes to for the last 3 hours and just can seam to get it working.

The error I get is "Syntax error in INSERT INTO statement"

Private Sub AddRecord_Click()

'Add the form details to the table

CurrentDb.Execute "INSERT INTO (Transactions (tDate,  category, transAmount, transDescription) " & _
    "VALUES & (" & _
    "'" & Me.txt_tDate & "', " & _
    "'" & Me.cmb_Category & "', " & _
    "'" & txt_TransAmount & "', " & _
    "'" & Me.txt_transDescription & "' " & _
    ")"


End Sub

The form has 4 fields as above with the tDate being set to Date() by default and all others as short text or number.

Any advice welcome.

Thanks

Smandoli
  • 6,919
  • 3
  • 49
  • 83
Simon
  • 3
  • 4
  • 1
    See this for instructions: http://stackoverflow.com/a/1099570/122139. The important thing is to use `Debug.Print` to put the final version of your query in the Immediate window; from there you can take it ordinary query builder and start trouble shooting. – Smandoli Nov 25 '15 at 05:34
  • Great link and answer @Smandoli. Goes straight to bookmarks and I'm never gonna have to type this stuff again. :) – Andre Nov 25 '15 at 11:09

2 Answers2

1

Remove the first & in this line:

"VALUES & (" & _

So it is:

"VALUES (" & _
Smandoli
  • 6,919
  • 3
  • 49
  • 83
0

Further, hardly all values are text, thus:

"#" & Format(Me.txt_tDate, "yyyy\/mm\/dd") & "#, " & _
"'" & Me.cmb_Category & "', " & _
"" & Str(txt_TransAmount) & ", " & _
"'" & Me.txt_transDescription & "' " & _

where Str will convert a decimal value to a string with dot as the decimal separator.

Gustav
  • 53,498
  • 7
  • 29
  • 55