Require selection from combo on checkbox?

Discussion in 'Microsoft Access' started by Steve B, Feb 28, 2008.

  1. Steve B

    Steve B Guest

    Hi - is it possible to set a form to require a selection from a combo if a
    check box is set to true?

    I've tried using the validation rule set to the check box name, but it
    doesn't work...
     
    Steve B, Feb 28, 2008
    #1
    1. Advertisements

  2. Steve B

    Jeff Boyce Guest

    Steve

    Since we're not there, we don't have any way to know HOW you "tried using
    the validation rule ..."

    If this were mine, I'd add a validation check in the form's BeforeUpdate
    event that ensured that there was a selection made in the combobox if the
    checkbox were true (and "Cancel"ed the update if there wasn't).

    By the way, you can make it easier for your users to understand that they
    need to do something with the combobox if you will add something like the
    following to the AfterUpdate event of the checkbox:

    Me!YourComboboxName.Enabled = (Me!YourCheckbox = True)

    This will enable/disable the combobox, depending on the status of the
    checkbox.

    You could even use:
    Me!YourComboboxName.SetFocus
    if the checkbox were true, to remind the user that they need to make a
    selection.

    Good Luck!

    Regards

    Jeff Boyce
    Microsoft Office/Access MVP

    "Steve B" <> wrote in message
    news:...
    > Hi - is it possible to set a form to require a selection from a combo if a
    > check box is set to true?
    >
    > I've tried using the validation rule set to the check box name, but it
    > doesn't work...
     
    Jeff Boyce, Feb 28, 2008
    #2
    1. Advertisements

  3. Steve B

    Steve B Guest

    Hi Jeff,

    Appolgies for the lack of info, I should no better as a whine to staff for
    lack of detail!

    I've added what I want for the time being by hiding the combo box by using
    the following in the form On current event

    Private Sub Form_Current()
    Me!part1.Visible = Me!Parts_requested
    End Sub

    and then on the check box After update event

    Private Sub Parts_requested_AfterUpdate()
    Me!part1.Visible = Me!Parts_requested
    End Sub

    But will also investigate your helpful suggestions

    Thank you for your time

    Steve



    "Jeff Boyce" <> wrote in message
    news:...
    > Steve
    >
    > Since we're not there, we don't have any way to know HOW you "tried using
    > the validation rule ..."
    >
    > If this were mine, I'd add a validation check in the form's BeforeUpdate
    > event that ensured that there was a selection made in the combobox if the
    > checkbox were true (and "Cancel"ed the update if there wasn't).
    >
    > By the way, you can make it easier for your users to understand that they
    > need to do something with the combobox if you will add something like the
    > following to the AfterUpdate event of the checkbox:
    >
    > Me!YourComboboxName.Enabled = (Me!YourCheckbox = True)
    >
    > This will enable/disable the combobox, depending on the status of the
    > checkbox.
    >
    > You could even use:
    > Me!YourComboboxName.SetFocus
    > if the checkbox were true, to remind the user that they need to make a
    > selection.
    >
    > Good Luck!
    >
    > Regards
    >
    > Jeff Boyce
    > Microsoft Office/Access MVP
    >
    > "Steve B" <> wrote in message
    > news:...
    >> Hi - is it possible to set a form to require a selection from a combo if
    >> a check box is set to true?
    >>
    >> I've tried using the validation rule set to the check box name, but it
    >> doesn't work...

    >
    >
     
    Steve B, Feb 28, 2008
    #3
  4. On Thu, 28 Feb 2008 19:48:47 -0000, "Steve B" <> wrote:

    >Hi - is it possible to set a form to require a selection from a combo if a
    >check box is set to true?
    >
    >I've tried using the validation rule set to the check box name, but it
    >doesn't work...


    Are you using a Form (good) or a table (much less good)? You can do the check
    in a Form's BeforeUpdate event:

    Private Sub Form_BeforeUpdate(Cancel as Integer)
    If Me!checkboxname = True Then
    If IsNull(Me!comboboxname) Then
    Msgbox "If the checkbox is checked you must select an item", vbOKOnly
    Cancel = True
    Me!comboboxname.SetFocus
    End If
    End If
    End Sub

    If you're using a table... well, don't; but if you are, you'll need to use the
    Table Validation rule, not field validation (which cannot refer to other
    fields). E.g.

    ([checkboxname] = True AND [combobox] IS NOT NULL) OR ([checkboxname] = False)
    --
    John W. Vinson [MVP]
     
    John W. Vinson, Feb 28, 2008
    #4
  5. Steve B

    Steve B Guest

    Cheers John & Jeff,

    Used both your solutions and everything is now perfect!

    Steve

    "John W. Vinson" <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in message
    news:blush:...
    > On Thu, 28 Feb 2008 19:48:47 -0000, "Steve B" <>
    > wrote:
    >
    >>Hi - is it possible to set a form to require a selection from a combo if a
    >>check box is set to true?
    >>
    >>I've tried using the validation rule set to the check box name, but it
    >>doesn't work...

    >
    > Are you using a Form (good) or a table (much less good)? You can do the
    > check
    > in a Form's BeforeUpdate event:
    >
    > Private Sub Form_BeforeUpdate(Cancel as Integer)
    > If Me!checkboxname = True Then
    > If IsNull(Me!comboboxname) Then
    > Msgbox "If the checkbox is checked you must select an item", vbOKOnly
    > Cancel = True
    > Me!comboboxname.SetFocus
    > End If
    > End If
    > End Sub
    >
    > If you're using a table... well, don't; but if you are, you'll need to use
    > the
    > Table Validation rule, not field validation (which cannot refer to other
    > fields). E.g.
    >
    > ([checkboxname] = True AND [combobox] IS NOT NULL) OR ([checkboxname] =
    > False)
    > --
    > John W. Vinson [MVP]
     
    Steve B, Feb 29, 2008
    #5
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jenn
    Replies:
    8
    Views:
    423
    Guest
    Dec 3, 2004
  2. Tony Girgenti
    Replies:
    5
    Views:
    343
    Ron2005
    Jan 9, 2006
  3. Paul
    Replies:
    6
    Views:
    335
    ruralguy via AccessMonster.com
    Jan 28, 2007
  4. Guest
    Replies:
    1
    Views:
    220
  5. Replies:
    1
    Views:
    342
    Douglas J. Steele
    Mar 30, 2007
Loading...

Share This Page