Populate formula results in Text Box based on Selection in Combo box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tmdrake
    New Member
    • Mar 2013
    • 43

    Populate formula results in Text Box based on Selection in Combo box

    My form includes a combo box where you select what type of test you ran. Based on that selection and the information entered into two additional text boxes, I need to populate a text box on the same form with the results.

    Here is the code I came up with so far:

    Code:
    Private Sub Text25_Click()
    If Me.Action = "NegativeTabWeld" Then
    If Me.PullForce >= 15 And Me.Nuggets >= 5 Then Me.Text25 = "Failed"
    If Me.PullForce <= 14 And Me.Nuggets <= 4 Then Me.Text25 = "Passed"
    Else
    If Me.Action = "PositiveTabWeld" Then
    If Me.PullForce >= 8 And Me.Nuggets >= 5 Then Me.Text25 = "failed"
    If Me.PullForce <= 7 And Me.Nuggets <= 4 Then Me.Text25 = "Passed"
    End If
    End Sub
    Help would be greatly appreciated.

    Toni
    Last edited by Rabbit; Mar 15 '13, 05:39 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    I'm not sure what your question is. Are you saying your code isn't working? What's wrong with it? Are you getting error messages? What are they?

    Comment

    • tmdrake
      New Member
      • Mar 2013
      • 43

      #3
      I'm not sure what you mean by code tags. No my code is not working,and I am getting the error message "Compile error: Block If without End If.

      Thanks

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        The way that you have your code makes it tough to see, but you are missing an End If
        Code:
        Private Sub Text25_Click()
        If Me.Action = "NegativeTabWeld" Then
        	If Me.PullForce >= 15 And Me.Nuggets >= 5 Then Me.Text25 = "Failed"
        	If Me.PullForce <= 14 And Me.Nuggets <= 4 Then Me.Text25 = "Passed"
        Else
        	If Me.Action = "PositiveTabWeld" Then
        		If Me.PullForce >= 8 And Me.Nuggets >= 5 Then Me.Text25 = "failed"
        		If Me.PullForce <= 7 And Me.Nuggets <= 4 Then Me.Text25 = "Passed"
        	End If
        
        End Sub
        You need to add an End If in line 10. However, I think it would be eaiser to see the logic of the code if you would use a Select Case statement instead of nested If-Then-Else statements, like this:
        Code:
        Private Sub Text25_Click()
        Select Case Me.Action
        	Case "NegativeTabWeld"
        		If Me.PullForce >= 15 And Me.Nuggets >= 5 Then Me.Text25 = "Failed"
        		If Me.PullForce <= 14 And Me.Nuggets <= 4 Then Me.Text25 = "Passed"
        	
        	Case "PositiveTabWeld"
        		If Me.PullForce >= 8 And Me.Nuggets >= 5 Then Me.Text25 = "failed"
        		If Me.PullForce <= 7 And Me.Nuggets <= 4 Then Me.Text25 = "Passed"
        	
        End Select
        End Sub

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Please read the posting guidelines in our faq: http://bytes.com/faq.php?faq=posting...ask_a_question. It tells you how to use code tags.

          Comment

          • tmdrake
            New Member
            • Mar 2013
            • 43

            #6
            Hi Seth,

            Sorry for the delay in responding. I used the Select code, however, nothing happens when I click on the field, could it possibly me because I'm using an unbound test box? I can't figure out why it's not working.

            Toni

            Comment

            • Seth Schrock
              Recognized Expert Specialist
              • Dec 2010
              • 2965

              #7
              Bound or unbound doesn't matter as you are just pulling the value that is in the control. Try putting a STOP right before your Select Case statement and then press Ctrl + G to open the Immediate window if it isn't already open. Then enter the following and tell us what the results are.
              Code:
              ?Me.Action
              ?Me.PullForce
              ?Me.Nuggets
              Then press F8 to step through the code one line at a time. It will tell you what path the code is going through.

              Comment

              • tmdrake
                New Member
                • Mar 2013
                • 43

                #8
                Unfortunately, I am not getting anything is the window that appears when I use Ctrl + G.

                Comment

                • Seth Schrock
                  Recognized Expert Specialist
                  • Dec 2010
                  • 2965

                  #9
                  So you aren't seeing the Immediate window at all? It should be at the bottom of the screen right below where you type in your code.

                  Comment

                  • tmdrake
                    New Member
                    • Mar 2013
                    • 43

                    #10
                    Thanks Seth, I was able to get it to work properly. I use the wrong Case "Name"

                    Toni

                    Comment

                    • Seth Schrock
                      Recognized Expert Specialist
                      • Dec 2010
                      • 2965

                      #11
                      That would do it. Glad you got it to work.

                      Comment

                      Working...