简体   繁体   中英

Access 2013 - Count Field Values While Adding Any New Fields

I need some help with this one and I can't seem to find the right question to ask to get an answer. We've got a table which is basically 1 primary key and 130+ software titles as Yes/No fields. I need to count the values (count) by Field Name which we can do with a simple aggregate query, but it's my understanding that would only return results for the fields that were included in the query when it was created. And as additional SW Fields are added to the table, I need to include counts for those also. Is there an easy way to accomplish this. My brain is fried! Thanks in advance.

PK SW1 SW2 SW3 ...
 1   1   0   1
 2   1   0   0
 3   0   1   1

So I would need to return:

 SW1 SW2 SW3
  2   1   2

And if SW4 was added to the table, include results for that field also.

Chris

Presuming you are using vb within access, you could get the field names and dynamically build the new query for any added fields.

The code below is from An example of how to get field names of a table . Once getting the field names, put them in an array and delete any that exist at the time the query was built. Then dynamically build a new query for any added fields. Probably more work than you were hoping for, but it will work.

Public Function fReturnFieldList(strTableName)
Dim rst As DAO.Recordset
Dim fld As Field
Dim strReturn As String

   On Error GoTo ProcError

   Set rst = CurrentDb.OpenRecordset(strTableName)
   For Each fld In rst.Fields
      strReturn = strReturn & ", " & fld.Name
   Next fld

EXIT_Proc:
   fReturnFieldList = Mid(strReturn, 3)
   On Error GoTo 0
   Exit Function

ProcError:
   strReturn = ", Cannot process " & strTableName
   Resume EXIT_Proc

End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM