select case not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mac rod
    New Member
    • Mar 2011
    • 35

    select case not working

    Hi everyone,

    could you please help me. i have a combo box that have the values "1st month", "2nd month" etc, a text box to put details such as weight, length and ccirc. what i want to do is when a user inputs the details and click a button, the text box wres, lres and ccircres will show the results such as "high", "low" or "normal". i tried the following code in the on click event of the button but it wont show anything...

    Code:
    Private Sub Command24_Click()
    Select Case Me.age
    Case "1st month"
    
    ' declares variables
    
    If weight <= 2.96 Then
    wres = "low"
    ElseIf weight >= 4.93 Then
    wres = "high"
    Else
    wres = "Normal"
    End If
    
    If length <= 49.1 Then
    lres = "short"
    ElseIf length >= 57 Then
    wres = "long"
    Else
    lres = "Normal"
    End If
    
    If hcircres <= 34.1 Then
    wres = "small"
    ElseIf hcircres >= 38.4 Then
    wres = "big"
    Else
    hcircres = "Normal"
    End If
    End Select
    
    Select Case Me.age
    Case "2nd month"
    
    ' declares variables
    
    If Me.[weight] <= 3.57 Then
    wres = "low"
    ElseIf Me.[weight] >= 5.84 Then
    wres = "high"
    Else
    wres = "Normal"
    End If
    
    If Me.[length] <= 52.1 Then
    lres = "short"
    ElseIf Me.[length] >= 60.3 Then
    wres = "long"
    Else
    lres = "Normal"
    End If
    
    If Me.[hcircres] <= 35.7 Then
    wres = "small"
    ElseIf Me.[hcircres] >= 39.8 Then
    wres = "big"
    Else
    hcircres = "Normal"
    End If
    End Select
    *its up to 12th months but the code is the same
    Last edited by NeoPa; Apr 25 '11, 03:10 PM. Reason: Added mandatory [CODE] tags
  • RuralGuy
    Recognized Expert Contributor
    • Oct 2006
    • 375

    #2
    I would start by only having *one* Select Case...End Select in the procedure.
    Code:
    Private Sub Command24_Click()
       Select Case Me.age
          Case "1st month"
    
             ' declares variables
    
             If Weight <= 2.96 Then
                wres = "low"
             ElseIf Weight >= 4.93 Then
                wres = "high"
             Else
                wres = "Normal"
             End If
    
             If length <= 49.1 Then
                lres = "short"
             ElseIf length >= 57 Then
                wres = "long"
             Else
                lres = "Normal"
             End If
    
             If hcircres <= 34.1 Then
                wres = "small"
             ElseIf hcircres >= 38.4 Then
                wres = "big"
             Else
                hcircres = "Normal"
             End If
    
    '----- Remove   End Select
    
    '----- Remove   Select Case Me.age
    
          Case "2nd month"
    
             ' declares variables
    
             If Me.[Weight] <= 3.57 Then
                wres = "low"
             ElseIf Me.[Weight] >= 5.84 Then
                wres = "high"
             Else
                wres = "Normal"
             End If
    
             If Me.[length] <= 52.1 Then
                lres = "short"
             ElseIf Me.[length] >= 60.3 Then
                wres = "long"
             Else
                lres = "Normal"
             End If
    
             If Me.[hcircres] <= 35.7 Then
                wres = "small"
             ElseIf Me.[hcircres] >= 39.8 Then
                wres = "big"
             Else
                hcircres = "Normal"
             End If
             
       End Select
    
    End Sub

    Comment

    • Mac rod
      New Member
      • Mar 2011
      • 35

      #3
      hi,
      Thanks for the quick reply. i tried it but still it's not showing any values.

      Comment

      • RuralGuy
        Recognized Expert Contributor
        • Oct 2006
        • 375

        #4
        Put the code in the AfterUpdate event of the ComboBox for more automatic operation. Make sure what is being returned with Me.Age By starting with a MsgBox that displays the value for you as a diagnostic.

        Comment

        • Mac rod
          New Member
          • Mar 2011
          • 35

          #5
          I put the code in the AfterUpdate event but still won't show any values. Sorry, i'm new to this but how do i make the MsgBox diagnostic?

          Comment

          • RuralGuy
            Recognized Expert Contributor
            • Oct 2006
            • 375

            #6
            Code:
            Private Sub Command24_Click()
               MsgBox "[" & Me.age & "]"
               Select Case Me.age

            Comment

            • Mac rod
              New Member
              • Mar 2011
              • 35

              #7
              it returns a message box that says "[]". that's it.

              Comment

              • RuralGuy
                Recognized Expert Contributor
                • Oct 2006
                • 375

                #8
                That means your Case structure will not work, which is what you are seeing. What is the Bound Column of your ComboBox and what do you have and the RowSource and RowSourceType?

                Comment

                • Mac rod
                  New Member
                  • Mar 2011
                  • 35

                  #9
                  RowSource = "1st month";"2nd month";"3rd month";"4th month";"5th month";"6th month";"7th month";"8th month";"9th month";"10th month";"11th month";"12th month";"15th month";"18th month";"24th month"

                  RowSourcceType = Value List

                  BoundColumn = 1

                  Comment

                  • Mac rod
                    New Member
                    • Mar 2011
                    • 35

                    #10
                    If it is of any help, i made the combo box by choosing the 2nd option in the wizard something like "i will type the values that i want". then typed it in the form view.

                    Comment

                    • RuralGuy
                      Recognized Expert Contributor
                      • Oct 2006
                      • 375

                      #11
                      Did you move the code to the AfterUpdate event of the ComboBox?

                      Comment

                      • Mac rod
                        New Member
                        • Mar 2011
                        • 35

                        #12
                        yup, still no values and the message box displays "[]"

                        Comment

                        • RuralGuy
                          Recognized Expert Contributor
                          • Oct 2006
                          • 375

                          #13
                          Dumb question but you are certain the ComboBox name is age right?

                          Comment

                          • Mac rod
                            New Member
                            • Mar 2011
                            • 35

                            #14
                            This is embarrassing...
                            actually it might be the answer! it was unbound and nothing is written in the control source. it's working now. thank you very much!

                            Comment

                            • RuralGuy
                              Recognized Expert Contributor
                              • Oct 2006
                              • 375

                              #15
                              That's Great! Glad we got it working finally.

                              Comment

                              Working...