ClearAll reset checkboxes

vba44

New Member
Joined
Jun 14, 2011
Messages
26
Good Morning,
I need some serious help programming a “Clear All” command button in an Access 2007 form. I have tried several codes found online without success. I have conceded to the fact that I’m lacking basic Access programming skills. Please help.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
I would like to program a command button in my form that will change all values in my table field from -1 to 0. The only thing happens when running these codes is the on-focus highlight disappears from the last checkbox focus point. No other changes were found.
<o:p> </o:p>
Table Name=MSTTable
Table Field Name=ChkBxA
Form Name=MST_Form4
Form Button name=ClearAll
<o:p> </o:p>
Code:
[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Private Sub ClearAll_Click()[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]DoCmd.RunSQL "UPDATE [MSTTable] SET ChkBxA=0;"[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]End Sub[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]
<o:p> </o:p>
Also tried this code as well
<o:p> </o:p>
Code:
[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]Private Sub ClearAll_Click()[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]DoCmd.RunSQL "UPDATE MSTTable SET ChkBxA=True;"[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]End Sub[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Although I would use CurrentDb.Execute instead of DoCmd.RunSQL, your second code should work. The one thing you would need though is to add

Me.Requery

after the DoCmd.RunSQL line so that the changes would be reflected in the form.
 
Upvote 0
This code is not working and I don't know what I'm doing wrong here.
Any help would be greately apreciated - please.

CODE
Private Sub ClearAll_Click()
CurrentDb.Execute "UPDATE NSTTable SET ChkBxA=True
Me. Requery
End Sub
/CODE
 
Upvote 0
When you say "the code is not working." Please explain what is not working. Is it sitting around having a cup of coffee? Is it skipping school? :biggrin:

Remember, we can't see what you see, so you have to provide enough information for us to make a rational guess as to what is going on. So, saying, "the code is not working" is like going to the doctor and being on 5 medications and saying - "Doc, the one medicine isn't working, what's wrong?" I think he would be asking WHICH medication isn't working? And how do you know?

So, anyway, one thing I did notice is that you are missing a double quote at the end of the SQL line. And, as Norie asked - because you need to use the FIELD name and not the control name.
 
Upvote 0

Forum statistics

Threads
1,224,544
Messages
6,179,430
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top