Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset -> "Too Few Parameters" error

Status
Not open for further replies.

bujin

MIS
Oct 2, 2000
144
GB
Help!

I keep getting a "Too few parameters. Expected 1" error on the line:

Set rst = dbs.OpenRecordset(qry, dbOpenDynaset)

The thing is, I've used almost exactly the same line in many other places throughout the database application I'm writing and I've never had this message before. I have no idea why it's suddenly decided to throw up this message. Can anyone shed some light on the subject?

The error occurs in the function I have pasted below (I have highlighted the actual line:


Private Function TraineeID(Surname As String) As String
Dim L As Byte, ID As String, IDNum As String, i As Integer
Dim dbs As Database, rst As Recordset, qry As String
L = Len(Surname)
ID = Surname
If L < 3 Then
For i = 1 To (3 - L)
ID = ID & &quot;X&quot;
Next i
End If
ID = Left(UCase(ID), 3)
Set dbs = CurrentDb
qry = &quot;SELECT [TraineeID] FROM [Trainee] &quot; & _
&quot;WHERE ([TraineeID] Like '&quot; & ID & &quot;*') &quot; & _
&quot;ORDER BY [TraineeID]&quot;

' THIS IS THE ERROR LINE:
Set rst = dbs.OpenRecordset(qry, dbOpenDynaset)

With rst
If .RecordCount > 0 Then
.MoveLast
IDNum = Right(![TraineeID], 4)
IDNum = CStr(CInt(IDNum) + 1)
Else
IDNum = &quot;0&quot;
End If
If Len(IDNum) < 4 Then
For i = 1 To (4 - Len(IDNum))
IDNum = &quot;0&quot; & IDNum
Next i
End If
End With
TraineeID = ID & IDNum
Set dbs = Nothing
End Function
 
D'oh!

Never mind, I got it!

Silly me, I was copying the code from an old version of the database, but I'd renamed the [TraineeID] field in the old database to [Id] in the new one! So the qry string was wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top