1

我有一个包含多个字段的访问表。我想通读所有行、所有字段,如果该字段包含 NULL,则设置默认值“”。我正在尝试使用字段定义通读表格,但无法找到该字段的现有值。

Dim fld As DAO.Field  
Dim t As DAO.TableDef   
Dim fldVal as string (test variable to see if I can find value of field)  

    For Each t In cd.TableDefs 

  If t.Name = "PERSONS" Then   
    For Each fld In t.Fields
     Just trying to find the existing value here
      fldVal = fld.Value  


      If fld.Type = 10 And IsNull(fld) = True Then  
         fld.Value = ""  
      End If  

   Next  
 End If  
Next
4

2 回答 2

1

我认为这可能会为PERSONS表做你想要的。

Dim cd As DAO.Database
Dim fld As DAO.Field
Dim t As DAO.TableDef
Dim rs As DAO.Recordset
Dim fldVal As Variant '(test variable to see if I can find value of field)

Set cd = CurrentDb
For Each t In cd.TableDefs
    If t.Name = "PERSONS" Then
        Set rs = cd.OpenRecordset(t.Name, dbOpenTable)
        Do While Not rs.EOF
            For Each fld In rs.Fields
                'Just trying to find the existing value here
                fldVal = fld.value

                If (fld.Type = dbText Or fld.Type = dbMemo) _
                        And IsNull(fld.value) = True Then
                   fld.value = ""
                End If
            Next fld
        rs.MoveNext
        Loop
    End If
Next t
于 2013-08-02T17:33:07.447 回答
0

改变

If fld.Type = 10 And IsNull(fld) = True Then

If fld.Type = 10 And IsNull(fld.Value) = True Then
于 2013-08-03T12:21:43.700 回答