Question

I'm using Access 2010, below is my code to retrieve all the column names where fields are empty (this works). But I would like to output the column names to a text box (Me.text1)

Setting Me.text1 = f.Name in the Do Loop will overwrite the last Column name if there's more than 1. So ideally I would like to have my text box populated with multiple values.

Any suggestions?

Dim Rst As DAO.Recordset
Dim f As DAO.Field
Dim db As DAO.Database

Set db = CurrentDb
Set Rst = db.OpenRecordset("Table1", dbOpenTable, dbOpenSnapshot)

With Rst
    Do While Not .EOF
       For Each f In .Fields
            If IsNull(f.Value) Then

             MsgBox "Field Name: " & f.Name

            End If
       Next

       .MoveNext
    Loop
End With

Rst.Close
Was it helpful?

Solution

Try:

Dim Rst As DAO.Recordset
Dim f As DAO.Field
Dim db As DAO.Database
Dim CReq As Boolean

Set db = CurrentDb
Set Rst = db.OpenRecordset("Table1", dbOpenTable, dbOpenSnapshot)
With Rst
    Do While Not .EOF
       CReq  = False
       For Each f In .Fields
            If IsNull(f.Value) Then
                Me.text1 = Me.text1 & IIf(CReq, ", ", "") & f.Name
                CReq  = True
            End If
       Next
       If CReq THEN           
           Me.text1 = Me.text1 & vbCrLf
       End If
       .MoveNext
    Loop
End With
Rst.Close
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top