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 & "X"
Next i
End If
ID = Left(UCase(ID), 3)
Set dbs = CurrentDb
qry = "SELECT [TraineeID] FROM [Trainee] " & _
"WHERE ([TraineeID] Like '" & ID & "*') " & _
"ORDER BY [TraineeID]"
' 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 = "0"
End If
If Len(IDNum) < 4 Then
For i = 1 To (4 - Len(IDNum))
IDNum = "0" & IDNum
Next i
End If
End With
TraineeID = ID & IDNum
Set dbs = Nothing
End Function
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 & "X"
Next i
End If
ID = Left(UCase(ID), 3)
Set dbs = CurrentDb
qry = "SELECT [TraineeID] FROM [Trainee] " & _
"WHERE ([TraineeID] Like '" & ID & "*') " & _
"ORDER BY [TraineeID]"
' 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 = "0"
End If
If Len(IDNum) < 4 Then
For i = 1 To (4 - Len(IDNum))
IDNum = "0" & IDNum
Next i
End If
End With
TraineeID = ID & IDNum
Set dbs = Nothing
End Function