Enabling options

Menes

Registered User.
Local time
Today, 22:24
Joined
Sep 21, 2007
Messages
16
I'm by no means an expert when it comes to using access and its many controls that are avaliable to use on forms. Thats why I've come here to seek your help.

I have a database that has been created by someone who has now left the company and it needs a little work done to it.

The ideal thing we would like to get working on form, is that we would like a number of options to be greyed out and only accessable when another option is ticked.

I'm not sure how to group these options together, nor an I sure how make them active only when an specific tick box is ticked. Any help would greatly appreciated on this matter.

Thanks for your time and patience.

Menes.
 
You're going to have to write some vba to handle this. My suggestion would be to write a public function in your form's code module that sets the 'enabled' property of the various check boxes on your form to yes (not grayed out) or no (grayed out) depending on the value in other checkboxes. And what do you want to have happen if someone checks a box that subsequently becomes grayed-out when they check a different checkbox? Uncheck it automatically? Leave it checked?

Then you'd call that function from the after update event of all the checkboxes that might have an impact on the grayed-out status of other checkboxes.

Perhaps something like

Code:
Public Sub Validate_Boxes()
'this bit sets the enabled property based on only one checkbox
If Me.Checkbox1 = -1 then 
   '-1 is the value of a checkbox if it is checked, 0 is the value if it is unchecked
   Me.Checkbox5 = 0
   Me.Checkbox5.Enabled = False
Else
   Me.Checkbox5.Enabled = True
End if

'this bit sets the enabled property of a checkbox based on two different 
'checkboxes and grays it out only if both are unchecked
If Me.Checkbox2 = -1 then 'first box is checked
   Me.Checkbox6.Enabled = True
Else 'first box is unchecked
   If Me.Checkbox3 = -1 then 'the second box is checked
      Me.Checkbox6.Enabled = True
   Else 'the second box is also unchecked so let's gray out the checkbox 
          'and make sure it is unchecked
      Me.Checkbox6 = 0
      Me.Checkbox6.Enabled = False 
   End If
End if
'and so on...
End Sub

Then you'd use something like

Code:
Private Sub Checkbox1_AfterUpdate()
Call Validate_Boxes
End Sub

for each of the checkboxes that you're testing the condition of in your code (in this example Checkbox 1, Checkbox 2, and Checkbox3)

You could also just place the relevant sections of the code directly into the after_update event of the various Checkboxes you're testing and skip using an all-in-one sub.
 
Hopfully this will explain a bit more as to what I'm trying to do. I had to use printscreen and just paste as a picture as no matter what I did I could get the file small enough using winzip to put the actual database on here so you could see it.

What I'm trying to do, is in this section of the form, that everything under the heading Database Information, will not be accessable to the user unless the database box is ticked. Once ticked they are then free to access the boxes as they want.

Hope this makes sence and the picture helps.

Thanks again.

Menes
 

Attachments

The code above should give you the general idea as to how to do this. Since it all hinges on only on checkbox, you would call the public sub (or have the code itself) in the afterupdate event of that checkbox and in the on_current event of the form.

The code in your puvblic sub (or event subs) would be something like

Code:
If Me.chkDatabases = -1 then
   Me.comboSystem.Enabled = True
   Me.comboProjectStatus = True
   'etc
Else
   Me.comboSystem.Enabled = false
   Me.comboProjectStatus = false
   'etc
End if

Of course you'll need to modify the names to match the control names on your form.
 
Look at response #9 in this thread. I spell out exactly how to do what you want, but it's using a listbox instead of a checkbox. Swap those out and you're good to go.
 

Users who are viewing this thread

Back
Top Bottom