Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access 访问VBA:CurrentDb.OpenRecordset上的类型不匹配_Ms Access_Vba - Fatal编程技术网

Ms access 访问VBA:CurrentDb.OpenRecordset上的类型不匹配

Ms access 访问VBA:CurrentDb.OpenRecordset上的类型不匹配,ms-access,vba,Ms Access,Vba,在下面的代码中,当我给vcount赋值时,我得到编译错误类型不匹配 我使用的代码是: Dim SQL As String Dim vcount As Integer SQL = " SELECT count(*) FROM [Data Processing List];" vcount = CurrentDb.OpenRecordset(SQL) CurrentDb.OpenRecordset返回一个记录集,而不是一个值 如果要访问记录集字段的值,可以使用fields集合中所需字段的.va

在下面的代码中,当我给vcount赋值时,我得到
编译错误类型不匹配

我使用的代码是:

Dim SQL As String
Dim vcount As Integer

SQL = " SELECT count(*) FROM [Data Processing List];"

vcount = CurrentDb.OpenRecordset(SQL)

CurrentDb.OpenRecordset
返回一个记录集,而不是一个值

如果要访问记录集字段的值,可以使用fields集合中所需字段的
.value
属性:

vcount = CurrentDb.OpenRecordset(SQL).Fields(0).Value

一些替代方法

使用TableDefs计算特定表中的行数:

Dim vcount As Integer

vcount = CurrentDb.TableDefs("[Data Processing List]").RecordCount
使用DCount

Dim vcount As Integer

vcount = DCount("*", "[Data Processing List]")
还有更多的方法。 请看这篇非常有趣的文章,其中讨论了几种方法,包括中小型表的性能结果:

DCount是一种非常简单的方法。