0

I am using the below SQL to try and put content in a textbox, to a different table. It was working until I added the text 43, and text 109 section

DoCmd.RunSQL "INSERT INTO tbl_EmailsSent (AccountNumber, Email1, ID, LoggedUser, LoggedDate) 
    VALUES (' " & Me.Text8 & "', 'Sent', ' " & Me.Text109 & ", ' " & me.Text43 "');

Can you see the mistake? Because I cant unfortunately

Andre
  • 25,063
  • 6
  • 31
  • 72
dmorgan20
  • 331
  • 6
  • 30
  • Use `Debug.Print`: [How to debug dynamic SQL in VBA](http://stackoverflow.com/questions/418960/managing-and-debugging-sql-queries-in-ms-access/1099570#1099570) -- you will find several errors (surplus spaces, missing quotes). – Andre Dec 01 '16 at 15:33
  • And please give your controls meaningful names, `Me.txtAccountNumber` is a lot better readable than `Me.Text8`. – Andre Dec 01 '16 at 15:37

1 Answers1

1

Yes, it's the date and the spaces ans missing quotes:

DoCmd.RunSQL "INSERT INTO tbl_EmailsSent (AccountNumber, Email1, ID, LoggedUser, LoggedDate) 
VALUES ('" & Me.Text8 & "', 'Sent', '" & Me.Text109 & "', #" & Format(Me!Text43.Value, "yyyy\/mm\/dd") & "#);"

No ID:

DoCmd.RunSQL "INSERT INTO tbl_EmailsSent (AccountNumber, Email1, LoggedUser, LoggedDate) 
VALUES ('" & Me.Text8 & "', 'Sent', '" & Me.Text109 & "', #" & Format(Me!Text43.Value, "yyyy\/mm\/dd") & "#);"
Gustav
  • 48,886
  • 6
  • 31
  • 51
  • Would this be right: DoCmd.RunSQL "INSERT INTO tbl_EmailsSent (AccountNumber, Email1, ID, LoggedUser, LoggedDate)VALUES ('" & Me.Text8 & "', 'Sent', '" & Me.Text109 & "', '" & Me.Text43 & "', #" & Format(Me!Text43.Value, "yyyy\/mm\/dd") & "#);" – dmorgan20 Dec 01 '16 at 15:46
  • I doubt it. It's rather that ID should be excluded as it most likely is an autonumber. – Gustav Dec 02 '16 at 07:28