+ Reply to Thread
Results 1 to 2 of 2

Thread: How to count text value from multiple columns

  1. #1
    Forum Contributor
    Join Date
    01-12-2004
    Location
    NY
    Posts
    92

    Question How to count text value from multiple columns

    Users review apps on a daily basis and on a form answer 13 questions with Yes; No; N/A. I need to count across all the Yes; No; and N/A per row (record).

    The following sample is how I need the info to display:

    App_ID....Q1....Q2....Q3...etc...Total_Y....Total_N.....Total_N/A
    1..............Yes...Yes...No.............2...............1..................0
    2..............No.....N/A...No............0................2.................1

    I wish I can use the countif function as in excel, but this is MS Access 2003. Is there any function, trick, or vba code for solving this problem?

    Thx in advance

    nrage21

  2. #2
    Forum Guru davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2007
    Posts
    1,879

    Re: How to count text value from multiple columns

    You can do it by changin the table using a recordset:

        Set rs = CurrentDb.OpenRecordset("your_Table", dbOpenDynaset)
            'Go to the first record.
            rs.MoveFirst
            'Loop through the recordset from first to last.
            Do Until rs.EOF
                intYesCount = 0
                intNoCount = 0
                intNACount = 0
                'Check the answer for the first question
                If rs!Q1 = "Yes" Then intYesCount = intYesCount + 1
                If rs!Q1 = "No" Then intNoCount = intNoCount + 1
                If rs!Q1 = "N/A" Then intNACount = intNACount + 1
                'Check the answer for the second question
                If rs!Q2 = "Yes" Then intYesCount = intYesCount + 1
                If rs!Q2 = "No" Then intNoCount = intNoCount + 1
                If rs!Q2 = "N/A" Then intNACount = intNACount + 1
                'Check the answer for each answer in the same pattern.
                '...
                '...
                '...
                'Put the found values into your total fields.
                rs!Total_Y = intYesCount
                rs!Total_N = intNoCount
                rs!Total_NA = intNACount
                rs.Update
            rs.MoveNext
    If you haven't used recordsets before, find some info via Google so you understand how they work, they are handy when you can't use SQL.

    If you set up your table differently, you could find your results using SQL.
    If you changed your table to three fields:
    App_ID; Question_ID; Answer
    You could then use the count function in SQL, and specify the app with the WHERE clause to find totals by app. You could also use the count function and specify the Question_ID in the where clause to find the totals by question.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0