运行时错误3061帮助(ms访问)

时间:2012-07-16 14:50:04

标签: sql ms-access runtime-error recordset

我一直在捣乱我的大脑,试图找出这个查询的错误,我只是没有看到它。我正在尝试打开一个记录集并且我一直收到运行时错误3061:“参数太少:预期为1.”

这是我的代码......

Dim ansRs As Recordset
Dim qRs As Recordset
Dim ansQuery As String
Dim qQuery As String
Dim i As Integer

qQuery = "Select * From TrainingQuizQuestions Where TrainingQuizID = (Select TrainingQuiz.TrainingQuizID From TrainingQuiz Where QuizName = Forms!MainMenu!txtVidName);"
ansQuery = "Select * From TrainingQuizQuestAns"
Set qRs = CurrentDb().OpenRecordset(qQuery)
Set ansRs = CurrentDb().OpenRecordset(ansQuery)

我从“Set qRs = CurrentDb()。OpenRecordset(qQuery)”行中得到错误。我将该查询复制并粘贴到访问中并运行它,它确切地返回了我想要在记录集中获取的内容,但是当我在VBA中运行它时,我得到了错误。我错过了一些非常简单的事吗?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

首先确保您的表单已打开,然后将表单引用放在引号之外。

 qQuery = "Select * From TrainingQuizQuestions Where TrainingQuizID = " _
   & "(Select TrainingQuiz.TrainingQuizID From TrainingQuiz Where QuizName = '" _
   & Forms!MainMenu!txtVidName) & "';"

表单值不适用于VBA中使用的记录集。