Public Function GetCounts(lngResponseID As Long) As Integer
Dim rst As DAO.Recordset
Dim strSQL As String
Dim intCount As Integer
Dim intRS As Integer
Dim intQuestion As Integer
' select the row that matches the passed Response ID.
strSQL = "SELECT * FROM owsResponseAnswer WHERE ResponseID = " & lngResponseID
' opens a DAO recordset to get the values from
Set rst = CurrentDb.OpenRecordSet(strSQL)
' sets the starting field number to look for filled in answers
intQuestion = 4
' Sets the loop to run through all of the fields of the recordset
Do Until intRS = rst.Fields.Count
' check to see if the field is null or empty and if not then add that to the count
If Len(rst(intQuestion) & "") <> 0 Then
intCount = intCount + 1
End If
' this increments the count for the iteration through the fields
intRS = intRS + 1
' this increments the field number for checking for a value or non value
intQuestion = intQuestion +1
Loop
' sets the value of the function to the count of fields with an answer
GetCounts = intCount
' closes the recordset which should be done
rst.Close
' removes the recordset variable from memory
Set rst = Nothing