|
如何解决“非法引用null"值的错误
我做了一个小程序,准备向WORD的表中填加数据库中的字段值,但是出现了一个小问题,当字有数据时,没有问题,但是当没有数据是提示我“非法引用NULL值”,我应该如何处理,就象邮件合并是,没数据,只显示为空的单元格。因为字段很多,不能每个都去判断是否为NULL
Sub startword()
On Error GoTo err_startword
Dim wrd As New Word.Application, isrunning As Boolean
Dim tableNew As Table, tableNew1 As Table
Dim dbMyDB As Database, rst As Recordset, rst1 As Recordset
isrunning = True
wrd.Documents.Open fileName:="D:\Documents and Settings\ysc\My Documents\djb"
wrd.Visible = True
Set tableNew = ActiveDocument.Tables(1)
Set dbMyDB = CurrentDb
Set rst = dbMyDB.OpenRecordset("jijan1", dbOpenSnapshot)
rst.MoveFirst
做以下的修改:
.Cell(1, 2).Range.Text = "" & rst("01")
.Cell(1, 2).FitText = True
.Cell(1, 4).Range.Text = "" & rst("02")
因为""与Null值连接时值为"","" 与其它值连接时值不变.
这可是我的妙招呵!
|
|