multiple selection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kevcar40

    #1

    multiple selection

    Hi
    i have a form that allows the user to select criteria for searching on
    what i am trying to create now is a search for shifts

    i have three check boxes on the form
    ashift
    bshift
    cshift

    i want the user to be able to select any one(only one) and return the
    relevent data (done this part)

    i also want the user to be able to select two shifts (but never three)
    ie
    ashift ashift
    bshift
    bshift or bshift or
    cshift
    and again return the relevent data

    can anyone please help me with this second part

    thanks

    kevin

  • Steve

    #2
    Re: multiple selection

    What you would do is put some code in the AfterUpdate event of each
    checkbox control to see if two other checkboxes are selected.

    Example:

    'Method: CheckChecks()
    'Purpose: Determines how many checkboxes are checked
    'Returns: Integer representing the number of checked checkboxes
    Public Function CheckChecks() As Integer
    'numChecked holds the number of checked boxes
    Dim numChecked as Integer
    If Me.AShift.Value =True Then
    'AShift is selected
    numChecked=numC hecked+1
    End If
    If Me.BShift.Value =True Then
    'BShift is selected
    numChecked=numC hecked+1
    End If
    If Me.CShift.Value =True Then
    'CShift is selected
    numChecked=numC hecked+1
    End If

    'Return the number of checked boxes
    CheckChecks=num Checked
    End Function

    In the AfterUpdate event of each checkbox, put in code like this:

    If CheckChecks>2 Then
    'Tell user to select only two boxes
    MsgBox "You can only check two boxes at a time", "Alert"
    'At this point, un-check the box the user has just selected
    Me.[AShift][BShift][CShift].Value=False
    End If

    When your user tries to check 3 boxes, he will get a message telling
    him to check only two of them. The box he just selected will be
    un-checked.

    *************** *************** *************** *
    Another way to do this is to disable the third checkbox when the user
    has already selected two of them. You could do this by putting code in
    the AfterUpdate event of each box like so:

    'In AShift's AfterUpdate
    If Me.BShift.Value =True Then
    Me.CShift.Enabl ed=False
    ElseIf Me.CShift.Value =True Then
    Me.BShift.Enabl ed=False
    End If

    'In BShift's AfterUpdate
    If Me.AShift.Value =True Then
    Me.CShift.Enabl ed=False
    ElseIf Me.CShift.Value =True Then
    Me.AShift.Enabl ed=False
    End If


    The problem with this method is that it would be kind of half-cartesian
    (you would have to check for two-thirds of the possible permutations of
    those checkboxes). This means that your code in each checkbox's
    AfterUpdate will grow exponentially as soon as you start adding
    checkboxes to that structure (i.e. if you decide you want to add a
    fourth shift).

    Comment

    • Thelma Lubkin

      #3
      Re: multiple selection

      Steve <theonesteve@gm ail.com> wrote:
      : What you would do is put some code in the AfterUpdate event of each
      : checkbox control to see if two other checkboxes are selected.

      : *************** *************** *************** *
      : Another way to do this is to disable the third checkbox when the user
      : has already selected two of them. You could do this by putting code in
      : the AfterUpdate event of each box like so:

      : 'In AShift's AfterUpdate
      : If Me.BShift.Value =True Then
      : Me.CShift.Enabl ed=False
      : ElseIf Me.CShift.Value =True Then
      : Me.BShift.Enabl ed=False
      : End If

      : 'In BShift's AfterUpdate
      : If Me.AShift.Value =True Then
      : Me.CShift.Enabl ed=False
      : ElseIf Me.CShift.Value =True Then
      : Me.AShift.Enabl ed=False
      : End If


      : The problem with this method is that it would be kind of half-cartesian
      : (you would have to check for two-thirds of the possible permutations of
      : those checkboxes). This means that your code in each checkbox's
      : AfterUpdate will grow exponentially as soon as you start adding
      : checkboxes to that structure (i.e. if you decide you want to add a
      : fourth shift).

      Another problem with this approach is that it takes away user's
      ability to change his/her mind. If CShift has become disabled,
      user can't decide to uncheck AShift and take CShift instead
      before asking for action...unless you write yet more code.
      --thelma

      Comment

      • kevcar40

        #4
        Re: multiple selection

        Thanks all

        Comment

        Working...