Run-time error 3061; Too few parameters. Expected 2

  • Thread starter Thread starter Song
  • Start date Start date
S

Song

Private Sub Sect_BeforeUpdate(Cancel As Integer)
Dim db As dao.Database
Dim rst As dao.Recordset
Set rst = CurrentDb.OpenRecordset("Select * From qryData Where
[sect] = '" & Me.Sect _
& "' And [TimeIn] >= #" & [Forms]![MainMenu].[From] & _
"# And [TimeOut] <= #" & [Forms]![MainMenu].[To] + 1 & "#")
If rst.EOF Then
MsgBox Me.Sect & " is not valid section #, or" & vbCrLf _
& "no student signed in " & Me.Sect & " during the period
specified.", , conAppName
Cancel = True
Else
Me.Course = rst![Course]
End If
Set db = Nothing
Set rst = Nothing

Exit_sect_BeforeUpdate:
Exit Sub
Err_sect_BeforeUpdate:
MsgBox Err.Description
Resume Exit_sect_BeforeUpdate

End Sub

Above code generate error message. Help is needed. Thanks.
 
Does qryData have parameters? If so, those parameters need to be
resolved first before the OpenRecordSet command.
 
Does qryData have parameters?  If so, those parameters need to be
resolved first before the OpenRecordSet command.

I solved parameters in qryData and simplified OpenRecordSet as
follows:

Set rst = CurrentDb.OpenRecordset("Select * From qryData Where
[sect] = '" & Me.Sect & "'")

But I still get same error message.
 
How did you "solve the parameters" in qryData? It doesn't sound as if
you've done that at all.

You might want to take a look at a sample on my website called
TooFewParameters.mdb
(http://www.rogersaccesslibrary.com/forum/topic234.html) which not only
explains why you're getting the "Too Few Parameters" error, but a couple of
ways to fix it.

It strike me that you either need to use a querydef to recreate qryData
before creating your recordset or you need to read the parameters
collection.

BTW, since you are creating a database variable, you might as well use it:

Dim db As dao.Database
Dim rst As dao.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("Select * From qryData Where
[sect] = '" & Me.Sect _ ...

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L


Does qryData have parameters? If so, those parameters need to be
resolved first before the OpenRecordSet command.

I solved parameters in qryData and simplified OpenRecordSet as
follows:

Set rst = CurrentDb.OpenRecordset("Select * From qryData Where
[sect] = '" & Me.Sect & "'")

But I still get same error message.
 
Back
Top