【发布时间】:2013-08-20 02:03:04
【问题描述】:
我有一个正在加载到记录集中的交叉表查询。然后,我将查询字段写入 Excel 电子表格。问题是根据查询结果可能不存在字段。
例如,我有以下行:
oSheet5.Range("F1").Value = rsB2("AK")
...这会将名为“AK”的记录集项目的值写入电子表格。但如果“AK”不存在,我会收到错误Item not found in this collection。
如何测试是否有名为“AK”的项目?
我试过了……
If rsB2("AK") Then
oSheet5.Range("F" & Count).Value = rsB2("AK")
End If
...但那没有用。
我也试过了……
If rsB2("AK") Is Nothing Then
oSheet5.Range("F" & Count).Value = ""
Else
oSheet5.Range("F" & Count).Value = rsB2("AK")
End If
...仍然是同样的错误。
有 50 多个项目/字段要检查 .. 美国的所有州以及一些额外内容。 谢谢!
【问题讨论】: