Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Jan 2002
    Location
    Massachusetts, USA
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Yes/No problem (2002 (XP))

    I have a table with 2 yes/no fields I want to make sure that they both can't be set to yes in the same record. Either one can be yes or both can be blank (No) boy not both Yes(Checked). Any help Please.

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Yes/No problem (2002 (XP))

    In the Before Update of the form you use to enter the data, use this code:
    <pre>Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.Check1 = True And Me.Check2 = True Then
    MsgBox "The 2 checkboxes may not be true in the same records"
    Cancel = True
    End If
    End Sub</pre>

    Francois

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Yes/No problem (2002 (XP))

    Another option is to set table-level validation rule:
    <pre>Not ([CHK1]=True And [CHK2]=True)</pre>

    Where CHK1 & CHK2 are the two Yes/No fields. Sample Validation text:
    <pre>CHK1 and CHK2 cannot both be True!</pre>

    Also recommend set default value of both Yes/No fields to False.

    HTH

  4. #4
    Star Lounger
    Join Date
    Jan 2002
    Location
    Massachusetts, USA
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Yes/No problem (2002 (XP))

    That looks good. I'll give it a shot Thanks

  5. #5
    Star Lounger
    Join Date
    Jan 2002
    Location
    Massachusetts, USA
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Yes/No problem (2002 (XP))

    So could I just put that rule in each validation in the table. If so will it pop the message if it is checked in a form?

  6. #6
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Yes/No problem (2002 (XP))

    Yes, if you set table level validation rule and create form based on table, the validation rule will still be triggered if you try to save record with both checkboxes checked. You would not have to set any additional validation rule for form or control. Note however that the table or field level validation rule will not appear on the checkbox control's property sheet, which displays the control's validation rule & validation text only.

    HTH

  7. #7
    Star Lounger
    Join Date
    Jan 2002
    Location
    Massachusetts, USA
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Yes/No problem (2002 (XP))

    Thanks Mark. That should do it just 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
  •