I wrote this routine to demo how the looping construct with recordset you provided in post1 could b modified to do what you are asking. Namely, to review a query and see if any of the fields were NULL or were zero length strings.
Code:
'---------------------------------------------------------------------------------------
' Procedure : boboivan
' Author : mellon
' Date : 21/02/2016
' Purpose : To see if there are any null or ZLS(zero length strings) in any fields in a query
'
' If any fields are NULL or ZLS, then increment variable emptyFieldCount
'---------------------------------------------------------------------------------------
'
Sub boboivan()
Dim sql As String 'the query sql
10 On Error GoTo boboivan_Error
20 sql = "SELECT ancestor.name, ancestor.id, ancestor.deathdate, ancestor.birthdate, ancestor.preregcode " _
& " FROM ancestor;"
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim emptyFieldCount As Integer
30 emptyFieldCount = 0
Dim i As Integer
40 Set db = CurrentDb
50 Set rs = db.OpenRecordset(sql, dbReadOnly)
60 With rs
70 Do While Not .EOF
80 If IsNull(![name]) Or Len(![name] & "") = 0 Then emptyFieldCount = emptyFieldCount + 1
90 If IsNull(![id]) Or Len(![id] & "") = 0 Then emptyFieldCount = emptyFieldCount + 1
100 If IsNull(![deathdate]) Or Len(![deathdate] & "") = 0 Then emptyFieldCount = emptyFieldCount + 1
110 If IsNull(![birthdate]) Or Len(![birthdate] & "") = 0 Then emptyFieldCount = emptyFieldCount + 1
120 If IsNull(![preregcode]) Or Len(![preregcode] & "") = 0 Then emptyFieldCount = emptyFieldCount + 1
130 rs.MoveNext
140 Loop
150 End With
160 Debug.Print IIf(emptyFieldCount > 0, "EmptyFieldsFound", "No EmptyFields")
170 On Error GoTo 0
180 Exit Sub
boboivan_Error:
190 MsgBox "Error " & Err.Number & " in line " & Erl & " (" & Err.Description & ") in procedure boboivan of Module AccessD_KillText"
End Sub
My table ancestor
Code:
name |
id |
deathdate |
birthdate |
preregcode |
sam |
|
12/03/1976 |
01/11/1922 |
21 |
bob |
1 |
13/03/1976 |
31/10/1922 |
44 |
jim |
2 |
17/09/1964 |
22/03/1944 |
63 |
ken |
45 |
07/02/2006 |
09/09/1999 |
82 |
TestPerson |
169 |
19/03/2009 |
21/07/1937 |
|
TestPerson |
170 |
19/03/2009 |
21/07/1937 |
|
TestPerson |
171 |
19/03/2009 |
21/07/1937 |
|
TestPerson172 |
172 |
19/03/2009 |
21/07/1937 |
|
TestPerson173 |
173 |
19/03/2009 |
21/07/1937 |
|
TestPerson174 |
174 |
19/03/2009 |
21/07/1937 |
|
TestPerson175 |
175 |
19/03/2009 |
21/07/1937 |
|
TestPerson176 |
176 |
19/03/2009 |
21/07/1937 |
|
Result of the routine:
EmptyFieldsFound
Good luck.