Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Related bit fields

    I have an Access 2007 form with two bit fields that are related. Is it possible to set them so that IF Field 1 is ticked THEN Field 2 is enabled ELSE Field 2 is disabled and set to zero?

  2. #2
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    You will just need to add some code to the After Update event on Field 1 to enable or disable it (and set it to 0), depending on the value of Field1.

  3. #3
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Thanks for your reply. Can you advise what the code should be, or can you direct me to a website with information on the code needed?

  4. #4
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    Admiting that the checkbox control is named theCheckBox and the textbox is named theTextBox, the following code added to the AfterUpdate event for the checkbox will do what you want:
    Code:
       If Me.theCheckBox.Value = True Then
            Me.theTextBox.Enabled = True
            Me.theTextBox.Value = 0
        Else
            Me.theTextBox.Enabled = False
            Me.theTextBox.Value = ""
        End If
    HTH

  5. #5
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Thanks for this. You refer to the two fields as "Checkbox" and "Textbox", but in my case, they are both checkboxes, so if Field 1 is ticked, then Field 2 should be enabled (so the user can then tick or untick it separately), else if Field 1 is unticked, then Field 2 should be disabled and set to zero. Will this work OK?

  6. #6
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    A checkbox has a value of True or False, not zero, so I guess you could do it like this:
    Code:
     If Me.theCheckBox1.Value = True Then
            Me.theCheckBox2.Enabled = True
     Else
            Me.theCheckBox2.Enabled = False
            Me.theCheckBox2.Value = False
        End If

  7. #7
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Thanks, that works fine when the user updates Checkbox 1.

    However, Checkbox 2 then remains enabled or disabled when the user moves to another record. How can I also make Checkbox 2 *initially* enabled or disabled on each record when it is displayed, depending on whether that record has Checkbox 1 enabled or disabled?
    Last edited by Murgatroyd; 2011-02-20 at 21:47.

  8. #8
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    Just add the same code to the OnCurrent event for the form.

  9. #9
    New Lounger
    Join Date
    Dec 2009
    Location
    San Francisco Bay Area
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ruirib View Post
    A checkbox has a value of True or False, not zero, so I guess you could do it like this:
    Code:
    If Me.theCheckBox1.Value = True Then
    Me.theCheckBox2.Enabled = True
    Else
    Me.theCheckBox2.Enabled = False
    Me.theCheckBox2.Value = False
    End If
    Just like to point out that a checkbox value can be 0 or -1 as well as False or True. They are the same in VBA code.
    Regards,
    Bill Mosca, Microsoft Access MVP
    That'll do IT http://thatlldoit.com

  10. #10
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    676
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Thanks for your replies, that works fine.

Posting Permissions

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