A97的DAO特性? [英] DAO peculiarity in A97?

查看:54
本文介绍了A97的DAO特性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,在下面的代码片段中,如果

tblCorrespondence中没有记录,我会在处理过程中收到错误

91。它抱怨没有设置对象

变量或With块变量。我已经仔细检查了代码,我不认为这是

就是这种情况。我想知道我的第231行中的代码是否因为qdfType17CorrespRecs

没有返回记录而有缺陷?


140使用MyDB

170设置qdfType17CorrespRecs = .CreateQueryDef(""," Select *

FROM tblCorrespondence;")

180使用qdfType17CorrespRecs

210''从QueryDef打开Recordset。

220设置rstType17CorrespRecs =

..OpenRecordset(dbOpenSnapshot)

230''使用rstType17CorrespRecs

231''如果.BOF = True则GoTo NoRecs

240''。移动首页

250''直到rstType17CorrespRecs.EOF

I have noticed, in the following code snippet, that if
tblCorrespondence has no records in it, I get an error
91 later during processing. It complains that an object
variable or a With block variable has not been set. I
have checked the code carefully and I don''t think this
is the case. I''m wondering if my code in line 231 might
be flawed in light of the fact that qdfType17CorrespRecs
returns no records?

140 With MyDB
170 Set qdfType17CorrespRecs = .CreateQueryDef("", "Select *
FROM tblCorrespondence;")
180 With qdfType17CorrespRecs
210 '' Open Recordset from QueryDef.
220 Set rstType17CorrespRecs =
..OpenRecordset(dbOpenSnapshot)
230 '' With rstType17CorrespRecs
231 '' If .BOF = True Then GoTo NoRecs
240 '' .MoveFirst
250 '' Do Until rstType17CorrespRecs.EOF

推荐答案

如果记录集没有记录,则BOF和EOF都将为真

时间。因此,在第231行,如果没有记录,那么BOF应该是真的。

但是,230到250行当前被注释掉,所以它们不是$>
正在执行。


你没有显示整个代码。确保您的结束语句行

在您期望的位置。如果你错过了一个,你应该得到一个

编译错误,但是如果它被放错了,你就不会得到编译错误但是

可能会得到错误你'得到。


仅供参考,第250行可以缩短为


Do Until .EOF


哪一行给出91错误?


-

Wayne Morgan

MS Access MVP

MLH < CR ** @ NorthState.net>在消息中写道

新闻:kb ******************************** @ 4ax.com ...
If the recordset has no records, both BOF and EOF will be true at the same
time. So, in line 231, if there are no records then BOF should be true.
However, lines 230 through 250 are currently "commented out", so they aren''t
executing.

You aren''t showing the entire code. Make sure your End With statements line
up where you expect them to. If you were missing one, you should get a
compile error, but if it is misplaced, you won''t get the compile error but
may get the error you''re getting.

FYI, line 250 can be shortened to

Do Until .EOF

Which line gives the 91 error?

--
Wayne Morgan
MS Access MVP
"MLH" <CR**@NorthState.net> wrote in message
news:kb********************************@4ax.com...
我注意到,在下面的代码片段中,如果
tblCorrespondence中没有记录,我会在处理过程中收到错误。它抱怨没有设置对象变量或With块变量。我已经仔细检查了代码,我不认为这是
。我想知道,鉴于qdfType17CorrespRecs
没有返回任何记录,第231行中的代码是否可能存在缺陷?

140使用MyDB
170 Set qdfType17CorrespRecs = .CreateQueryDef(""," Select *
FROM tblCorrespondence;")
180 with qdfType17CorrespRecs
210''从QueryDef打开Recordset。
220设置rstType17CorrespRecs =
.OpenRecordset(dbOpenSnapshot)
230''使用rstType17CorrespRecs
231''如果.BOF = True则GoTo NoRecs
240''MoveFirst
250'' Do Until rstType17CorrespRecs.EOF
I have noticed, in the following code snippet, that if
tblCorrespondence has no records in it, I get an error
91 later during processing. It complains that an object
variable or a With block variable has not been set. I
have checked the code carefully and I don''t think this
is the case. I''m wondering if my code in line 231 might
be flawed in light of the fact that qdfType17CorrespRecs
returns no records?

140 With MyDB
170 Set qdfType17CorrespRecs = .CreateQueryDef("", "Select *
FROM tblCorrespondence;")
180 With qdfType17CorrespRecs
210 '' Open Recordset from QueryDef.
220 Set rstType17CorrespRecs =
.OpenRecordset(dbOpenSnapshot)
230 '' With rstType17CorrespRecs
231 '' If .BOF = True Then GoTo NoRecs
240 '' .MoveFirst
250 '' Do Until rstType17CorrespRecs.EOF



这是否可以代替第231行:

如果.RecordCount = 0那么

转到NoRecs

结束如果


这里有许多不同于我的事情。你不需要创建一个

临时查询,只需要查询语句中的OpenRecordset。并且使用

dbOpenDynaset(特别是如果你计划MoveFirst。)


尝试:

Dim MyDB As DAO.Database

Dim rstType17CorrespRecs作为DAO.Recordset

Dim strSql As String


strSql =" Select * FROM tblCorrespondence;"

设置rstType17CorrespRecs = MyDB.OpenRecordset(strSql)

如果rstType17CorrespRecs.RecordCount> 0然后

''在这里做你的东西。

结束如果

rstType17CorrespRecs.Close


-

Allen Browne - 微软MVP。西澳大利亚州珀斯。

访问用户提示 - http:// allenbrowne.com/tips.html

回复群组,而不是mvps dot org的allenbrowne。


" MLH" < CR ** @ NorthState.net>在消息中写道

新闻:kb ******************************** @ 4ax.com ...
Does this work in place of line 231:
If .RecordCount = 0 Then
Go To NoRecs
End If

There''s bunch of things different here than I would do. You don''t need a
temp query created, just OpenRecordset on the query statement. And use
dbOpenDynaset (esp. if you plan to MoveFirst.)

Try:
Dim MyDB As DAO.Database
Dim rstType17CorrespRecs As DAO.Recordset
Dim strSql As String

strSql = "Select * FROM tblCorrespondence;"
Set rstType17CorrespRecs = MyDB.OpenRecordset(strSql)
If rstType17CorrespRecs.RecordCount > 0 Then
''do your stuff here.
End If
rstType17CorrespRecs.Close

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.net> wrote in message
news:kb********************************@4ax.com...
我注意到,在下面的代码片段中,如果
tblCorrespondence中没有记录,我会在处理过程中收到错误。它抱怨没有设置对象变量或With块变量。我已经仔细检查了代码,我不认为这是
。我想知道,鉴于qdfType17CorrespRecs
没有返回任何记录,第231行中的代码是否可能存在缺陷?

140使用MyDB
170 Set qdfType17CorrespRecs = .CreateQueryDef(""," Select *
FROM tblCorrespondence;")
180 with qdfType17CorrespRecs
210''从QueryDef打开Recordset。
220设置rstType17CorrespRecs =
.OpenRecordset(dbOpenSnapshot)
230''使用rstType17CorrespRecs
231''如果.BOF = True则GoTo NoRecs
240''MoveFirst
250'' Do Until rstType17CorrespRecs.EOF
I have noticed, in the following code snippet, that if
tblCorrespondence has no records in it, I get an error
91 later during processing. It complains that an object
variable or a With block variable has not been set. I
have checked the code carefully and I don''t think this
is the case. I''m wondering if my code in line 231 might
be flawed in light of the fact that qdfType17CorrespRecs
returns no records?

140 With MyDB
170 Set qdfType17CorrespRecs = .CreateQueryDef("", "Select *
FROM tblCorrespondence;")
180 With qdfType17CorrespRecs
210 '' Open Recordset from QueryDef.
220 Set rstType17CorrespRecs =
.OpenRecordset(dbOpenSnapshot)
230 '' With rstType17CorrespRecs
231 '' If .BOF = True Then GoTo NoRecs
240 '' .MoveFirst
250 '' Do Until rstType17CorrespRecs.EOF





我通常将此构造用于DAO循环,包括A97

设置rs = db.Openrecordset(....)

do而不是rs.eof

[...]

rs.movenext

循环


处理无记录条件适当,不使用

GoTo。你的代码使用.BOF检查没有记录,这可能不是

正确。


星期六,2005年12月31日09:02:01 -0500 ,MLH< CR ** @ NorthState.net>写道:

I usually use this construct for DAO loops, including A97

Set rs = db.Openrecordset (....)
do while not rs.eof
[...]
rs.movenext
loop

It handles the no-record condition appropriately, without using a
GoTo. Your code uses .BOF to check for no records, which may not be
correct.

On Sat, 31 Dec 2005 09:02:01 -0500, MLH <CR**@NorthState.net> wrote:
我注意到,在下面的代码片段中,如果
tblCorrespondence中没有记录,我会在处理过程中收到错误。它抱怨没有设置对象变量或With块变量。我已经仔细检查了代码,我不认为这是
。我想知道,鉴于qdfType17CorrespRecs
没有返回任何记录,第231行中的代码是否可能存在缺陷?

140使用MyDB
170 Set qdfType17CorrespRecs = .CreateQueryDef(""," Select *
FROM tblCorrespondence;")
180 with qdfType17CorrespRecs
210''从QueryDef打开Recordset。
220设置rstType17CorrespRecs =
.OpenRecordset(dbOpenSnapshot)
230''使用rstType17CorrespRecs
231''如果.BOF = True则GoTo NoRecs
240''MoveFirst
250''直到rstType17CorrespRecs.EOF
I have noticed, in the following code snippet, that if
tblCorrespondence has no records in it, I get an error
91 later during processing. It complains that an object
variable or a With block variable has not been set. I
have checked the code carefully and I don''t think this
is the case. I''m wondering if my code in line 231 might
be flawed in light of the fact that qdfType17CorrespRecs
returns no records?

140 With MyDB
170 Set qdfType17CorrespRecs = .CreateQueryDef("", "Select *
FROM tblCorrespondence;")
180 With qdfType17CorrespRecs
210 '' Open Recordset from QueryDef.
220 Set rstType17CorrespRecs =
.OpenRecordset(dbOpenSnapshot)
230 '' With rstType17CorrespRecs
231 '' If .BOF = True Then GoTo NoRecs
240 '' .MoveFirst
250 '' Do Until rstType17CorrespRecs.EOF




**********************
JA ************** @ telusTELUS.net

删除真实电子邮件的大写字母
http:// www .geocities.com / jackso有关MS Access安全性信息的nmacd /


这篇关于A97的DAO特性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆