Results 1 to 4 of 4
  1. #1
    jbeets is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2020
    Posts
    94

    Include cbo in calculation IF the selection equals Yes else ignore


    Hello,
    I have a form that uses the responses in each CBO to determine a total score of a file. I am trying to add in some logic for 1 specific CBO (A_Injury_Qualifyer) that says IF A_Injury_Qualifyer = "Yes" then include in the overall score calculation Else ignore the response in A_Injury_Qualifyer and calculate everything else. Basically, I want the reviewer to give credit with a Yes response and not penalized or given credit with a No response.
    Here is the code I have that works fine without the added locgic.

    Code:
    Private Sub btnTotalScore_Click()Dim c As Control, nYes As Long, nNo As Long, nNA As Long
    nYes = 0
    nNo = 0
    nNA = 0
    
    
    For Each c In Me.Controls
        Select Case c.Name
            Case "cboStatus", "cboEmployee", "cboManager", "cboQuarter", "A_Coverage_Qualifyer", "A_APD_Qualifyer"
            Case Else
    
    
        If TypeName(c) = "ComboBox" Then
            If c.Value = "Yes" Then nYes = nYes + 1
            If c.Value = "No" Then nNo = nNo + 1
            If c.Value = "N/A" Then nNA = nNA + 1
        End If
    End Select
    Next c
    
    
    
    
    txtTotalScore = Format((nYes) / (nYes + nNo), "Percent")
    Thank you in advance for any help or guidance you can provide!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    are you trying to count the values for all fields in 1 record,
    or
    all needed fields in all records. If this, youd run a query and count the fields.

  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Like this?

    Code:
    Private Sub btnTotalScore_Click()
        Dim c As Control, nYes As Long, nNo As Long, nNA As Long
        nYes = 0
        nNo = 0
        nNA = 0
        
        
        For Each c In Me.Controls
            Select Case c.Name
                Case "cboStatus", "cboEmployee", "cboManager", "cboQuarter", "A_Coverage_Qualifyer", "A_APD_Qualifyer"
                Case Else
                    If TypeName(c) = "ComboBox" Then
                    
                        If c.Value = "Yes" Then nYes = nYes + 1
                        
                        If c.Name <> "A_Injury_Qualifyer" Then
                            If c.Value = "No" Then nNo = nNo + 1
                            If c.Value = "N/A" Then nNA = nNA + 1
                        End If
                        
                    End If
            End Select
        Next c
    
    
        txtTotalScore = Format((nYes) / (nYes + nNo), "Percent")
    End Sub

  4. #4
    jbeets is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Feb 2020
    Posts
    94
    kd2017 - This seems to be exactly what I was looking for! Thank you for your quick response and taking the time to help me!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Keeps asking for an equals sign....
    By lonesoac0 in forum Programming
    Replies: 11
    Last Post: 08-18-2019, 11:31 AM
  2. Use Combo Box selection in a calculation
    By sra2786 in forum Access
    Replies: 5
    Last Post: 10-11-2017, 10:49 PM
  3. Grouping AVG, want to ignore calculation question.
    By McArthurGDM in forum Programming
    Replies: 5
    Last Post: 06-21-2015, 12:53 PM
  4. First Row Equals Header Problem
    By wcrimi in forum Access
    Replies: 4
    Last Post: 11-11-2014, 01:25 PM
  5. Record selection based on calculation
    By WEJ in forum Programming
    Replies: 5
    Last Post: 05-30-2013, 01:05 PM

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
  •  
Other Forums: Microsoft Office Forums