Microsoft Access表单文本框以保留多个值

时间:2014-05-08 01:37:02

标签: access-vba ms-access-2010

我使用Access 2010,下面是我的代码,用于检索字段为空的所有列名称(这样可行)。但我想将列名输出到文本框(Me.text1)

如果超过1,在Do循环中设置Me.text1 = f.Name将覆盖最后一个列名。所以理想情况下我希望我的文本框中填充多个值。

有什么建议吗?

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

1 个答案:

答案 0 :(得分:1)

尝试:

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