我有一个包含多个字段的访问表。我想读取所有行,所有字段,如果字段包含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
答案 0 :(得分: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
答案 1 :(得分:0)
更改
If fld.Type = 10 And IsNull(fld) = True Then
到
If fld.Type = 10 And IsNull(fld.Value) = True Then