If you are trying to Update fields in a table and then open a form (with Where Clause) that will display the table and expect to see changes made with only two lines of code, I think it is not possible.
I assume you have a Form open and have ticked a check box or done something on the form and now want to make the change to one or more records in a table ??
If the form is Bound to a table, then most likely the form control you click on is also bound. This cahnge can be done just like that ie, the form allows you to change the table, normally one record at a time.
If you really want all the records in a table to be changed on teh click of a command Button on a form, thenyou will need some code to make this happen.
Think about what is happening here...
You need to Interupt the operator needs which often means reading the data on the Form.
This done by two lines of code like this.
Code:
Dim MyVariable As String
MyVariable = Me.yourcontrolname
This is simplistic as it assumes the data is string, not date or number.
Also, yourcontrolname is not what you type.
Then you need to define your Recordset and Database.
Then you need to decide on a method to make the change.
Then you make the change
Maybe before I type a copy of MS Access Help you explain in more detail what you trying to achieve and what you have done so far.
Check124, which is presumably a check box on your form, needs to be referenced outside of the SQL string (i.e. not inside the quotes that delimit the string);
Code:
Dim strSQL As String
strSQL = "Update Listings Set [Lot_Selected] = -1 Where [Garage] = " & Me.Check124
CurrentDb.Execute strSQL, dbFailOnError
I suspect Sean has identified at least part of the problem. Since the error specified 2, if you still get an error double check the spelling of everything, and the data type of Garage.
Thanks, guys!
Too bad there isn't a Paypal donation button for me to drop 99cents everytime someone gives me a working line of code! Totally worth it!
-Dave
The error is basically telling you there's something it can't resolve. Double check the spelling of the table and field names. What is the data type of Garage, and what is in Check124 (descriptive names pay off in the long run)? This may help debug the SQL: