Multiple fields options controlling one checkbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mayala12
    New Member
    • Feb 2013
    • 7

    Multiple fields options controlling one checkbox

    I have a situation where I have a checkbox that is supposed to check if one of two criteria happens.

    I can get it to check if one of the criteria is true but I'm having issues having it check if the other is.

    So if one of the two cases below is true the chkSizeableUpch arge checkbox should be checked. But what's happening is that it's only checking the box if the txtDoorWidth option triggers it. It's ignoring the height, which I'm guessing is because it checks the width later, but I need it to do it based on either of them, like an Or in between but not sure how to write it. Any ideas or help would be appreciated.

    Code:
    Select Case frm.TxtDoorHt.Value
            
                Case 78, 84, 90, 96, 102, 108
                    frm.chkSizeableUpcharge.Value = False
                Else
                    frm.chkSizeableUpcharge.Value = True
            End Select
           
            'Only valid door widths - 8, 9, 10, 12, 16, 18
            Select Case frm.TxtDoorWidth.Value
            
                Case 96, 108, 120, 144, 192, 216
                        frm.chkSizeableUpcharge.Value = False
                Case Else
                        frm.chkSizeableUpcharge.Value = True
            
            End Select
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    That's because your else option in your second select is going to override whatever the first select did. What you'll want to do is nest your selects.

    Comment

    • mayala12
      New Member
      • Feb 2013
      • 7

      #3
      Thank you, I understand what you're saying but when I try and nest them the way that I think that would normally work with a If Then Else scenario, it doesn't work, it still will check the box when the height is non-standard if I put height first when I nest it, than it will check the box for the height if it's wrong but not for the width if it's wrong and the height is ok. Same if I swap them, it will do the width but not the height.

      I know I'm probably nesting it wrong, so any guidance would be appreciated. I have had to pick up this programming thing on my own, and this program has a ton of code in it.

      My attempt based on what I think you said is below.

      Code:
       Select Case frm.TxtDoorHt.Value
              
                      Case 78, 84, 90, 96, 102, 108
                              frm.chkSizeableUpcharge.Value = False
                     
                          Select Case frm.TxtDoorWidth.Value
                              Case 96, 108, 120, 144, 192, 216
                                  frm.chkSizeableUpcharge.Value = False
                          End Select
                          
                      Case Else
                          frm.chkSizeableUpcharge.Value = True
                      
              End Select

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You nested it in the wrong place. It needs to be nested in the the Else.

        Comment

        • mayala12
          New Member
          • Feb 2013
          • 7

          #5
          Thank you for the clarification. I redid it per the below but now both of them have to be true in order to trigger the check box instead of either of them being true.

          I changed the code, I hope in the proper way per your instruction to the below. Do you have any further ideas?
          Code:
          Select Case frm.TxtDoorHt.Value
                  
                          Case 78, 84, 90, 96, 102, 108
                                  frm.chkSizeableUpcharge.Value = False
                                                               
                          Case Else
                              Select Case frm.TxtDoorWidth.Value
                                  Case 96, 108, 120, 144, 192, 216
                                      frm.chkSizeableUpcharge.Value = False
                                  Case Else
                                      frm.chkSizeableUpcharge.Value = True
                              End Select
                              
                          
                  End Select

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Sorry, I didn't notice the way you were setting your true/false. You can either flip your conditions or use your first nested example and include an else statement.

            Comment

            • vijay6
              New Member
              • Mar 2010
              • 158

              #7
              Hey mayala12, in your first code put your second select case statement inside a if statement only if frm.chkSizeable Upcharge.Value is False. i.e., After first select case statement still if chkSizeableUpch arge CheckBox is not checked then execute your second select case statement.

              Comment

              • mayala12
                New Member
                • Feb 2013
                • 7

                #8
                Thank you everyone for your help. I think I have solved this after thinking about it. There is another place in the code where we are doing something similar that I found. I have sort of copied that idea and below is what I came up with and it seems to be working. The feedback was helpful in working through different scenarios and figuring out why it wasn't working etc.

                Code:
                Select Case frm.TxtDoorHt.Value
                        
                            Case 78, 84, 90, 96, 102, 108
                                bSizeableHtChk = False
                            Case Else
                                bSizeableHtChk = True
                               
                        End Select
                                                                                    
                        Select Case frm.TxtDoorWidth.Value
                            Case 96, 108, 120, 144, 192, 216
                                bSizeableWdthChk = False
                            Case Else
                                bSizeableWdthChk = True
                        End Select
                        
                        If bSizeableHtChk = True And bSizeableWdthChk = True Then
                            frm.chkSizeableUpcharge.Value = True
                        ElseIf bSizeableHtChk = True And bSizeableWdthChk = False Then
                            frm.chkSizeableUpcharge.Value = True
                        ElseIf bSizeableHtChk = False And bSizeableWdthChk = True Then
                            frm.chkSizeableUpcharge.Value = True
                        Else
                            frm.chkSizeableUpcharge.Value = False
                        End If

                Comment

                • vijay6
                  New Member
                  • Mar 2010
                  • 158

                  #9
                  Hey mayala12, its sounds good. You found a way to solve your problem by yourself. If you want then still you can optimize your code.

                  Code:
                  If bSizeableHtChk = False And bSizeableWdthChk = False Then
                              frm.chkSizeableUpcharge.Value = False
                  Else
                              frm.chkSizeableUpcharge.Value = True
                  End If

                  Comment

                  Working...