I have an Access 2007 database application that I’m taking over. In one of the tables there are 13 fields, and I need to run a query to see if any of those fields contains a zero. The typical entry in these fields are numbers like 0.8, 1.4, 0.5, 9.1, 0.0 – I just need to know the COUNT of how many fields, for each of the around 2,500 records, contains a 0.0. I have:
vb Code:
  1. Dim db As DAO.Database
  2. Set db = Access.Application.CurrentDb
  3. Dim rsCount As DAO.Recordset
  4. Dim sSQL As String
  5. Dim Counter As Integer
  6. Dim strPOCode As String
  7. Set rsCount = CurrentDb.OpenRecordset("SELECT * FROM table")
  8. Do While Not rsCount.EOF
  9.  
  10.     strPOCode = rsCount.Fields("FieldName")
  11.    
  12.     If rsCount.Fields("Field1").Value = 0 Then
  13.        Counter = Counter + 1
  14.     End If
  15.    
  16.     If rsCount.Fields("Field2").Value = 0 Then
  17.        Counter = Counter + 1
  18.     End If
  19.  
  20.     If rsCount.Fields("Field3").Value = 0 Then
  21.        Counter = Counter + 1
  22.     End If
  23.  
  24. 'etc etc on through all 13 fields
  25.  
  26.     sSQL = "UPDATE table "
  27.     sSQL = sSQL & "SET  CounterFieldInTable = " & Counter
  28.     sSQL = sSQL & " WHERE FieldName = '" & strPOCode & "' "
  29.     'Debug.Print sSQL
  30.     db.Execute sSQL
  31.     Counter = 0
  32.     rsCount.MoveNext
  33. Loop
This works just fine....but I'm not real well versed in Access VBA (or any other kind of VBA for that matter) so I'm wondering if there is a better way. It loops through all 2,500 and change records pretty quickly....it just looks a little "sloppy".

Thanks.