[RESOLVED] Sum function using Combobox data-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] Sum function using Combobox data

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2017
    Posts
    42

    Resolved [RESOLVED] Sum function using Combobox data

    I have 3 textboxes and 1 combobox.
    txtpresence = calculated via other textboxes
    txtProduction = enters by user
    cboScore = 0 -25 selected by user

    txtEfficiency = populated with summation result

    Code:
    Private Sub txtPresence_Change()
     If Me.txtPresence.Value <> vbNullString Then
        If IsNumeric(Me.txtPresence.Value) = True Then
           If Me.txtProduction.Value <> vbNullString Then
              If IsNumeric(Me.txtProduction.Value) = True Then
                 If Me.cboScore.Value <> vbNullString Then
                    If IsNumeric(Me.cboScore.Value) = True Then
                Me.txtEfficiency.Value = [CDbl(Me.txtProduction.Value) / CDbl(Me.txtPresence.Value) * 75] + CDbl(Me.cboScore.Value)
                    End If
                 End If
              End If
           End If
        End If
     End If
    End Sub
    
    Private Sub txtProduction_Change()
     If Me.txtProduction.Value <> vbNullString Then
        If IsNumeric(Me.txtProduction.Value) = True Then
           If Me.txtPresence.Value <> vbNullString Then
              If IsNumeric(Me.txtPresence.Value) = True Then
                 If Me.cboScore.Value <> vbNullString Then
                    If IsNumeric(Me.cboScore.Value) = True Then
                 
                 Me.txtEfficiency.Value = [CDbl(Me.txtProduction.Value) / CDbl(Me.txtPresence.Value) * 75] + CDbl(Me.cboScore.Value)
                    End If
                 End If
              End If
           End If
        End If
     End If
    End Sub
    
    Private Sub cboScore_Change()
     If Me.cboScore.Value <> vbNullString Then
       If IsNumeric(Me.cboScore.Value) = True Then
          If Me.txtPresence.Value <> vbNullString Then
             If IsNumeric(Me.txtPresence.Value) = True Then
                If Me.txtProduction.Value <> vbNullString Then
                   If IsNumeric(Me.txtProduction.Value) = True Then
                 
                 Me.txtEfficiency.Value = [CDbl(Me.txtProduction.Value) / CDbl(Me.txtPresence.Value) * 75] + CDbl(Me.cboScore.Value)
                    End If
                 End If
              End If
           End If
        End If
     End If
    End Sub
    It gives error on this line for cboScore declaration
    Code:
                Me.txtEfficiency.Value = [CDbl(Me.txtProduction.Value) / CDbl(Me.txtPresence.Value) * 75] + CDbl(Me.cboScore.Value)
    Should i use another term instead of CDbl(Me.cboScore.value) or there's something else wrong in my code?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    22,876

    Re: Sum function using Combobox data

    CDbl(Me.cboScore.value)
    should be fine, as long as the combobox value is a valid numeric value

    what error do you get?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2017
    Posts
    42

    Re: Sum function using Combobox data

    I shouldn't use brackets in code .i just replaced brackets with parentheses

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.