如何在使用链接表时获取记录数或记录数 [英] How to get recordcount or number of records when using linked tables

查看:85
本文介绍了如何在使用链接表时获取记录数或记录数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用链接表时获得从

a查询返回的记录数的准确计数。


我有一个访问2003数据库作为另一个访问2003

数据库的前端,只包含表格。我已将

前端的表格链接到后端数据库。

我试图将表单的记录源设置为由
建立的查询
用户缩小范围但我不想显示表格如果

没有与查询匹配的记录。所以,

给予


Dim db作为数据库

Dim rst作为记录集

Dim sql As String

Dim MyRecordSource As String

Dim RecordCountVariable As Integer


设置db = CurrentDb()

设置rst = db.OpenRecordset(sqlF98,dbOpenDynaset,dbReadOnly)


如果不是(rst.BOF或rst.EOF)那么

rst.MoveLast

RecordCountVariable = rst.RecordCount

rst.MoveFirst''(如果你打算做其他事情

这里)

否则

RecordCountVariable = 0

结束如果

如果RecordCountVariable = 0那么

MsgBox (没有记录符合搜索条件)

否则

Me.RecordSource = sqlF98

结束如果

rst.recordcount总是返回零(0),但我知道有记录

,因为当我设置me.recordsource = sqlF98时,过滤器设置正确

我只得到一个数据子集。


.recordcount上的帮助表明它不能在链接表上工作。你用什么

属性获取查询中返回的记录数?


提前付款


罗伯特

How do you get an accurate count of the number of records returned from
a query when using linked tables.

I have an access 2003 database as a front end to another access 2003
database that contains only tables. I have linked the tables for the
front end to the back end database.
I am trying to set the recordsource of a form to a query established by
the user to narrow the scope but I don''t want to display the form if
there are no records that match the query. So,
given

Dim db As Database
Dim rst As Recordset
Dim sql As String
Dim MyRecordSource As String
Dim RecordCountVariable As Integer

Set db = CurrentDb()

Set rst = db.OpenRecordset(sqlF98, dbOpenDynaset, dbReadOnly)

If Not (rst.BOF Or rst.EOF) Then
rst.MoveLast
RecordCountVariable = rst.RecordCount
rst.MoveFirst ''(If you are going to do something else
here)
Else
RecordCountVariable = 0
End If
If RecordCountVariable = 0 Then
MsgBox ("No records match search criteria")
Else
Me.RecordSource = sqlF98
End If
rst.recordcount always returns zero (0) but I know there are records
because when I set me.recordsource = sqlF98 the filter is set correctly
and I only get a subset of the data.

Help on .recordcount indicates it doesn''t work on linked tables. What
property do you use then to get # of records returned in a query?

Thanks in Advance

Robert

推荐答案

难道不是这样的吗?

"如果不是(rst.BOF或rst.EOF)然后

总是评估为真,因为你在打开记录集后直接打开rst.BOF?或者我错了。

如果使用AND会发生什么,因为在空记录集中BOF = EOF(或

....)

为什如果数据集很大,你的

方法可能需要一些时间,因为你必须移动到最后一个记录

并返回以便能够计算它们。

Mike

Isn''t it so that
" If Not (rst.BOF Or rst.EOF) Then "
always evaluates to True since you are at rst.BOF directly after
opening the recordset? Or am I wrong.
What happens if you use AND, since in an empty record set BOF = EOF (or
....)

Why don''t you use DCount() or SELECT count() FROM .... to get the
number of records in the database. If the dataset is large your
approach may take some time since you have to move to the last record
and back in order to be able to count them.
Mike


从recordcount上的另一个帖子借用一些代码,我在设置后立即插入了

rst.openrecordset


strMsg =" BOF:" &安培; rst.BOF& " ;. EOF: &安培; rst.EOF& _

。 RecordCount: &安培; rst.RecordCount

MsgBox strMsg

Me.RecordSource = sqlF98

strMsg = BOF:True。 EOF:是的。 ReocrdCount:0


但是,当我将表格''的记录源设置为rst时,我会显示16条记录

。发生了什么事?

Borrowing some code from another post on recordcount, I inserted the
following immediately after the set rst.openrecordset

strMsg = "BOF: " & rst.BOF & ". EOF: " & rst.EOF & _
". RecordCount: " & rst.RecordCount
MsgBox strMsg
Me.RecordSource = sqlF98
strMsg = BOF: True. EOF: True. ReocrdCount: 0

However, when I set the form''s recordsource to rst, I get 16 records
displayed. what is going on?


正如Mike所说..

你必须转到最后的记录然后回来
在您使用recordcount属性之前再次



就像这样


rst.MoveLast

rst。 MoveFirst

rst.RecordCount

As Mike said..
You have to move to last record and back
again before u used the recordcount property

like this

rst.MoveLast
rst.MoveFirst
rst.RecordCount


这篇关于如何在使用链接表时获取记录数或记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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