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

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.
 
G

ghetto_banjo

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

Song

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.
 
R

Roger Carlson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top