Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I change checkbox state when I change records?

Status
Not open for further replies.

steelmtn

Programmer
Oct 10, 2002
3
US
I am not new to programming, but I am new to VBA and still kind of a rookie with Access 2002. I am working with a table (oh yeah, I’m still learning the VBA/Access lingo – if anything in this post looks really weird I am probably calling it the wrong thing). The table holds info about the products that my company sells. There is a form that most of the people working with the database use to add new products, update pricing, etc. I was asked to add a checkbox to this form that will lock down the three price fields (cost, MSRP, and sale price) to prevent someone from making an accidental change. When the box is not checked, the price fields are locked; when it is checked the fields unlock. The default should be for the box to be unchecked when the form loads.

Here’s what I do have working: the fields are in fact locked when the box is unchecked and the fields unlock when the box is checked. No problem there.

This is what doesn’t work:

1) when the form loads for the first time the checkbox is ‘grayed out’ and the fields are not locked. If you check on the box it starts working and the fields lock and unlock the way I want them to. How do make the checkbox assume the unchecked state when the form loads?

2) I want the checkbox to revert back to the unchecked state when the user moves to the next record. For example, someone is looking at record 103 and checks the box to change the price. They then move on to record 104 without unchecking the pricelock box in 103. When they return to record 103 I want the checkbox to be unchecked. Ideally this checkbox update should happen when the user leaves record 103, not when they return to the record.

Hope this makes sense and I hope someone out there can help. Thanks in advance for your help!
 
OK, there are a number of ways to tackle this. You can employ a tag on the control and act upon the tag based on some code in a function.

Or you can lock the controls on the OnCurrent Event
me("Cost").enabled=false
me("MSRP").enabled=False
me("saleprice").enabled=false

naturally you need to use the names you assigned for the controls. I like the enabled since it will dim the control.

Now on your check box set the default value in properties to false and add the code to enable the controls based on the check mark state on the afterupdate event.

Afterupdate Event of the check mark control
If Me("check29") = True Then
me("Cost").enabled=true
me("MSRP").enabled=true
me("saleprice").enabled=true
Else
me("Cost").enabled=false
me("MSRP").enabled=False
me("saleprice").enabled=false
End If

I don't know if this is what you want but it's a start. Life's a journey enjoy the ride...

jazzz
 
Sorry it took me so long to get back to you. The solution you provided worked great. Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top