Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through fields in a query 1

Status
Not open for further replies.

daklem

Technical User
Sep 28, 2003
23
0
0
Hi all,

Is there a way to loop through the fields in a DAO recordset without refering to the field names. I would like to be able to determine the number of fields in the recordset and loop through all the fields checking for nulls on the fly.

Thank you for your help.
 
If you don't refer to the field names, how will you know where the null is if/when you find one?


Randy
 
randy 700

I just need to know if there are any nulls, not which field is null
 
Code:
Dim rs As DAO.Recordset
Dim fd As DAO.Field
Set rs = db.OpenRecordset("Select * From tbl")

For Each fd in rs.Fields
   If IsNull(fd.Value) Then
      [COLOR=black cyan]' Found a Null in field[/color]
   End If
Next fd
 
Hi!

Like this:

Dim fld As Field
Dim rst As DAO.Recordset
Dim strFields As String
Dim intCounter As Integer

intCounter = 0
strFields = ""
Set rst = CurrentDb.OpenRecordset("YourQuery", dbOpenDynaset)

For Each fld In rst.Fields
intCounter = intCounter + 1
If IsNull(fld.Value) = True Then
strFields = strFields & fld.Name & ";"
End If
Next fld

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Golom,

Thanx, I will try that and let you know how it works.
 
Of course, that looks at only the first record of the recordset. To look at all of them you would need
Code:
Dim rs As DAO.Recordset
Dim fd As DAO.Field
Set rs = db.OpenRecordset("Select * From tbl")

Do Until rs.EOF
   For Each fd in rs.Fields
      If IsNull(fd.Value) Then
         Debug.Print "Field " & fd.Name & " IS NULL" 
      End If
   Next fd
   rs.MoveNext
Loop
 
Thank you Golom and Jerby,

Just what I needed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top