我正在将表格从Excel导入Access
导入功能完美无缺,但空字段覆盖了Access中的默认0设置。
我导入的表中的数据正在其他地方的计算字段中使用,无法使用空字段进行计算。
问题:如何在导入后在Access中将多个空字段设置为0?
答案 0 :(得分:1)
要设置单个字段,请使用UPDATE查询:
UPDATE myTable SET Column1 = 0 WHERE Column1 IS NULL
要设置多个字段,请在循环中使用多个UPDATE查询,例如
Sub CleanUp()
Dim arFields As Variant
Dim vField As Variant
Dim S As String
' The field names that can be NULL after import
arFields = Array("Column1", "otherColumn", "[yet another one]")
For Each vField In arFields
S = "UPDATE myTable SET " & vField & " = 0 WHERE " & vField & " IS NULL"
Debug.Print S
CurrentDb.Execute S
Next vField
End Sub