在Access中运行SQL语句计数记录集 - 运行时错误3075

时间:2015-03-18 19:48:31

标签: ms-access access-vba

我是Access的新手并尝试计算数据集中的行数并使用以下代码。我收到一个运行时错误,这似乎是因为SQL语句。我从查询中复制了它,所以我不确定我做错了什么。

Function RecordCount()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim sqlstring As String
Dim x As Integer
Dim FindRecordCount As Integer

sqlstring = "SELECT Question_List.Questions, Question_List.[Freq] FROM Question_List WHERE (((Question_List.ClientCd)=`" & [Forms]![TestControlCreate]![ComClient] & "));"


   Set db = CurrentDb

   Set rst = db.OpenRecordset(sqlstring) 

   FindRecordCount = rst.RecordCount

Return
End Function

1 个答案:

答案 0 :(得分:0)

应该按以下方式重建SqlString:

 sqlstring = "SELECT Question_List.[Questions], Question_List.[Freq] FROM Question_List WHERE Question_List.[ClientCd]= '" & [Forms].[TestControlCreate].[ComClient] & "';"