Enabling a form control

peted

Registered User.
Local time
Today, 07:47
Joined
Jan 31, 2008
Messages
18
Hi. I’m very new to Access and have a question which I’m sure is easy to answer, but which I just can’t work out at all. I’ve designed a form in which there’s a check box for a field called ‘other’ and a text box for a field called ‘other_specify’. What I want to do is have the other_specify box greyed out until the ‘other’ check box is ticked.
I’ve had a play around and wrote the following event procedure for the after update option of the check box:
Private Sub Other_check_box_AfterUpdate()

If Other_check_box.Value = True Then
Other_specify_text_box.Enabled = True
Else
Other_specify_text_box.Enabled = False
Other_specify_text_box = Null

End If

End Sub

That works to some extent, but it makes the change for every record on the form, i.e. if I tick the check box when dealing with record one the text box becomes enabled, but when I go to the next record although the check box isn’t ticked, the text box is enabled. I’ve tried to work out what’s going wrong, and it was fun to begin with, but now it’s just annoying as I’m getting nowhere slowly. Any one got any ideas? Thanks
 
Hello!

I've recently had to deal with a similar thing, I put an edit button on the form, so the form has to decide for each record whether the edit button as pressed or not.

Try copying your exact code into the Form's "Oncurrent Event". This runs that code on every new record. So when you switch to a different record on the form it will run your code, check to see if that checkbox is checked or not, and then run the appropriate code.
 
Thanks, but how do I do that exactly? I'm very new to this lark.
 
Hello again,

I apologize for being vague in my reply. Please go into your coding for the checkbox After Update and copy it (Highlight and CTRL-C etc.).

Open up the your form in design view.

Right click on the dark grey area outside of the form area, or in the little box at the top left, and then click "Properties". You should now see a properties box come up with the title "Form" or something extremely similar.

Click on the "Event" Tab, and then click in the line beside "On Current" (this should be your top option).

Click the three dots to the right, and then click "Code Builder". You should see the following:

Private Sub Form_Current()

End Sub

Paste the code you copied earlier between these two lines so it should look like this:

Private Sub Form_Current()

If Other_check_box.Value = True Then
Other_specify_text_box.Enabled = True
Else
Other_specify_text_box.Enabled = False
Other_specify_text_box = Null

End If

End Sub

And then save the code and test, and it should work. Hope this helps, let me know!
 
Fantastic! That worked an absolute treat.
Thank you very much.
 
Simplest way to do this, on a Continuous or Datasheet view form, is to use Conditional Formatting.

Select Other_specify_text_box

Goto Format - Conditional Formatting

Under Conditiona1 select Expression Is

In the condition box enter [Other_check_box] = False

Now click on the Enable icon. It's the one on the far right (to the right of the big A)
 

Users who are viewing this thread

Back
Top Bottom