0

I am attempting to delete records from a table based on a listbox selection in my form. The table is DailyLog & UserLoggedOn where username is a variable based on user. The listbox is Me.lstRespLBPers. The field is the table is RespLBPerson. I keep getting "Expected end of Statement" error message with the word WHERE highlighted. What am I doing wrong. Code is listed below:

sql = "DELETE * FROM DailyLog_" & UserLoggedOn WHERE [RespLBPerson] <> Me.LstRespLBPers

I tried the code and expected the records to be deleted from the table but got the error message.

pjenks25
  • 1
  • 1
  • What's the DBMS you're currently using? – lemon Dec 14 '22 at 20:44
  • 1
    You are not concatenating the last part of the string properly. Presumably you want something like `sql = "DELETE * FROM DailyLog_" & UserLoggedOn & " WHERE [RespLBPerson] <> Me.LstRespLBPers"` (note the second `&` and the quotation marks), although I'm not sure what language is being used here. – EdmCoff Dec 14 '22 at 20:44
  • Constructing SQL statements by including text directly from an input form can be very dangerous. Please see this article on SQL injection attacks: https://stackoverflow.com/questions/332365/how-does-the-sql-injection-from-the-bobby-tables-xkcd-comic-work – STLDev Dec 15 '22 at 03:18

0 Answers0