設(shè)為首頁收藏本站Access中國

Office中國論壇/Access中國論壇

 找回密碼
 注冊

QQ登錄

只需一步,快速開始

返回列表 發(fā)新帖
查看: 1826|回復(fù): 2
打印 上一主題 下一主題

如何解決“非法引用null"值的錯(cuò)誤

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2002-11-25 21:23:00 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
我做了一個(gè)小程序,準(zhǔn)備向WORD的表中填加數(shù)據(jù)庫中的字段值,但是出現(xiàn)了一個(gè)小問題,當(dāng)字有數(shù)據(jù)時(shí),沒有問題,但是當(dāng)沒有數(shù)據(jù)是提示我“非法引用NULL值”,我應(yīng)該如何處理,就象郵件合并是,沒數(shù)據(jù),只顯示為空的單元格。因?yàn)樽侄魏芏,不能每個(gè)都去判斷是否為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


With tableNew
    .Cell(1, 2).Range.Text = rst("01")
    .Cell(1, 2).FitText = True
    .Cell(1, 4).Range.Text = rst("02")
    End With


If isrunning = False Then
wrd.Quit
End If
Exit Sub
err_startword:
If Err.Number = 429 Then
Set wrd = CreateObject("word.application")
isrunning = True
Resume Next
Else
MsgBox Err.Number & "" & Err.Description
Exit Sub
End If
End Sub
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 分享淘帖 訂閱訂閱

點(diǎn)擊這里給我發(fā)消息

2#
發(fā)表于 2002-11-26 00:42:00 | 只看該作者
空值,你可以用一個(gè)空格代替。
3#
發(fā)表于 2002-11-27 00:16:00 | 只看該作者
如何解決“非法引用null"值的錯(cuò)誤
我做了一個(gè)小程序,準(zhǔn)備向WORD的表中填加數(shù)據(jù)庫中的字段值,但是出現(xiàn)了一個(gè)小問題,當(dāng)字有數(shù)據(jù)時(shí),沒有問題,但是當(dāng)沒有數(shù)據(jù)是提示我“非法引用NULL值”,我應(yīng)該如何處理,就象郵件合并是,沒數(shù)據(jù),只顯示為空的單元格。因?yàn)樽侄魏芏,不能每個(gè)都去判斷是否為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")

因?yàn)?quot;"與Null值連接時(shí)值為"","" 與其它值連接時(shí)值不變.

這可是我的妙招呵!
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則

QQ|站長郵箱|小黑屋|手機(jī)版|Office中國/Access中國 ( 粵ICP備10043721號(hào)-1 )  

GMT+8, 2025-7-17 00:29 , Processed in 0.086527 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復(fù) 返回頂部 返回列表