Clearing a field........

chef_tim

Registered User.
Local time
Today, 09:36
Joined
Dec 16, 2004
Messages
77
Hi All, I'm looking for a simple way to clear a all of a specific field in a table (check box). I've put a control on the form but I'm not sure what/how to make it work. Any ideas/suggestions welcome. Thanks, Tim
 
Clear all of a specific field in a table.... Like, make every checkbox be no longer checked?

That could be done as an update query (which you can do in the query design grid pretty easily.)

Create a new query. You have the chance to add tables to this new query. Add the table containing your targeted field. By default a NEW query comes up as a SELECT query. On the toolbar, find the drop-down that changes the type of query. Make it an UPDATE query.

In the first column of the query grid, there is a FIELD drop-down. Select the name of the field. In the UpdateTo row under that field, put NO. (If it is a "real" checkbox, it is a Yes/No field. NO is the "clear" state.) Or enter whatever other value is appropriate.

OK, save the query with a name like RESETFIELDXYZ (or whatever other name makes sense to you.) Short is good, descriptive is good, but sadly those two attributes are contrary to each other. So pick a compromise name that you can remember.

Now, on the form from which you wish to do the reset, in design view, create a control button with the button wizard enabled at the time. It will ask you what you want to do. Tell it to run a query. Name the query using the name of the UPDATE query you just created.

Now, one last trick. The wizard, when it built the button, also built a bit of VBA code for you in the Button_OnClick routine, which it placed in the form's class module. Find the code in that routine that runs the query. (You'll see the query name in cleartext on a line, probably a DoCmd.RunQuery ....)

After that line, add two more lines

Me.Requery
Me.Refresh

Close, compile, and save the module. You should be good to go after that.

NOTE: Me.{anything} has to be used from the class module because in a general module, the "Me" construct has no meaning. Therefore you cannot make a general subroutine to handle this situation quite so simply.
 
Thank you for a very good answer. It works like a charm. What does the "Me.Requery and Me.Refresh" mean or do. I put them in but I'd just like to know what they do. Thanks, Tim
 
chef_tim said:
What does the "Me.Requery and Me.Refresh" mean or do. I put them in but I'd just like to know what they do.

A good tip is to put the cursor next to the command you want to know about and press F1. It opens up the help for that keyword - giving explanations, similar keywords, and - at times - examples of the keyword in use.
 

Users who are viewing this thread

Back
Top Bottom