I don't exactly know where I'm going wrong but I have a textbox where a user enters a value and that value is used to query my table to delete all records that don't match the entered value but it doesn't work.
User enters text into a 'myTxtBx' textbox and clicks a button to remove all records that are not equal to the 'myTxtBx' value. These are just random names I'm giving for this example.
See code below:
CurrentDb.Execute "DELETE FROM [MyTable] " _
& "WHERE [fieldName] <> '" & Me.myTextBox & "'"
This just doesn't work. When I run the code, all records in the table are deleted. The thing is that when using a combo box, it works perfectly but not when using a textbox.
Here is an example of using a combo box to delete records based on the user entered text value. This works with no issues. I don't know why the textbox control doesn't work. It would seem that this should work and the only difference is that a textbox is being used to get the value for use in query instead of a combo box.
CurrentDb.Execute "DELETE FROM [MyTable] " _
& "WHERE [fieldName]<> '" & Me.myCBO & "'"
I'd really appreciate any help you could provide. Thanks!!