Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    May 2008
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Contingent Control disabling (Access 2002)

    In a form I am trying to disable or enable a control depending on whether a check box is true or false. I can't find an Form event that will help because the control will be changed within the record. I have tried triggering an update so that the AfterUpdate Event would do it, but neither Save REcord or Refresh seem to do the trick. I can't use any event on the control I want to disable because you can't disable a control which has the focus.
    Any ideas gratefully received.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Contingent Control disabling (Access 2002)

    You need to use two events for this:

    - The After Update event of the check box, so that the control is enabled/disabled when the user clicks the check box:

    Private Sub MyCheckBox_AfterUpdate()
    Me.OtherControl.Enabled = Me.MyCheckBox
    End Sub

    where MyCheckBox is the name of the check box, and OtherControl is the name of the control to be enabled/disabled.

    - The On Current event of the form, so that the control is enabled/disabled when the user moves to another record:

    Private Sub Form_Current()
    Me.OtherControl.Enabled = Me.MyCheckBox
    End Sub

    I have assumed that the control should be enabled if the check box is ticked. If it is to be disabled when the check box is ticked, use

    Me.OtherControl.Enabled = Not Me.MyCheckBox

    in both procedures.

  3. #3
    Lounger
    Join Date
    May 2008
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Contingent Control disabling (Access 2002)

    It works brilliantly, but I don't understand why! I had got stuck on the thought that an event lined to a control could only influence that control, and I can't see what the code is saying, I suppose I was expecting If/Else language.
    Anyway I am very grateful for the solution.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Contingent Control disabling (Access 2002)

    Me.MyCheckBox returns the value of the check box, i.e. True if the check box is ticked, and False if the check box is clear.

    Me.OtherControl.Enabled is also a True/False value: True if the control is enabled, False if the control is disabled.

    Since both values are True/False, there is no need to use an If ... Then ... Else ... construction, you can assign one value directly to the other.

    Me.OtherControl.Enabled = Me.MyCheckBox

    says: if the check box is ticked, set Enabled to True, and if the check box is clear, set Enabled to False.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •