3061: Too few parameters. expected 1 serializing query

samcoinc

Registered User.
Local time
Today, 20:19
Joined
Sep 26, 2001
Messages
49
I am having a problem with serializing a query. I am using this function below from http://msaccesstips.com/2010/01/auto-numbering-in-query-column/

The query runs great (numbers correctly) until I try to add a criteria to the query - Then I get 3061: Too few parameters. expected 1. The criteria is from a drop down on a form. ([Forms]![Check Register form]![Text2]) and in the query I added this parameter to it. The query works fine without the qryseq function added - it filters the data correctly. But it seems that somhow I need to add the parameter to the function also...

I don't know how to do that. (hope that made sense)

thanks
sam

Code:
Dim varArray() As Variant, i As Long

Public Function QrySeq(ByVal fldvalue, ByVal fldName As String, ByVal qryname As String) As Long
'-------------------------------------------------------------------
'Purpose: Create Sequence Numbers in Query in a new Column
'Author : a.p.r. pillai
'Date : Dec. 2009
'All Rights Reserved by www.msaccesstips.com
'-------------------------------------------------------------------
'Parameter values
'-------------------------------------------------------------------
'1 : Column Value - must be unique Values from the Query
'2 : Column Name  - the Field Name from Unique Value Taken
'3 : Query Name   - Name of the Query this Function is Called from
'-------------------------------------------------------------------
'Limitations - Function must be called with a Unique Field Value
'            - as First Parameter
'            - Need to Save the Query after change before opening
'            - in normal View.
'-------------------------------------------------------------------
Dim k As Long
On Error GoTo QrySeq_Err

restart:
If i = 0 Or DCount("*", qryname) <> i Then
Dim j As Long, db As Database, rst As Recordset

i = DCount("*", qryname)
ReDim varArray(1 To i, 1 To 3) As Variant
Set db = CurrentDb
Set rst = db.OpenRecordset(qryname, dbOpenDynaset)
For j = 1 To i
    varArray(j, 1) = rst.Fields(fldName).Value
    varArray(j, 2) = j
    varArray(j, 3) = fldName
    rst.MoveNext
Next
rst.Close
End If

If varArray(1, 3) & varArray(1, 1) <> (fldName & DLookup(fldName, qryname)) Then
    i = 0
    GoTo restart
End If

For k = 1 To i
If varArray(k, 1) = fldvalue Then
    QrySeq = varArray(k, 2)
    Exit Function
End If
Next

QrySeq_Exit:
Exit Function

QrySeq_Err:
MsgBox Err & " : " & Err.Description, , "QrySeqQ"
Resume QrySeq_Exit

End Function
 
I winged it from some other microsoft references... Seems to be working correctly.

sam

Code:
Dim varArray() As Variant, i As Long

Public Function QrySeq(ByVal fldvalue, ByVal fldName As String, ByVal qryname As String) As Long
'-------------------------------------------------------------------
'Purpose: Create Sequence Numbers in Query in a new Column
'Author : a.p.r. pillai
'Date : Dec. 2009
'All Rights Reserved by www.msaccesstips.com
'-------------------------------------------------------------------
'Parameter values
'-------------------------------------------------------------------
'1 : Column Value - must be unique Values from the Query
'2 : Column Name  - the Field Name from Unique Value Taken
'3 : Query Name   - Name of the Query this Function is Called from
'-------------------------------------------------------------------
'Limitations - Function must be called with a Unique Field Value
'            - as First Parameter
'            - Need to Save the Query after change before opening
'            - in normal View.
'-------------------------------------------------------------------
Dim k As Long
On Error GoTo QrySeq_Err

restart:
If i = 0 Or DCount("*", qryname) <> i Then
Dim j As Long, db As Database, rst As Recordset
Dim strSearchName As String
Dim qdfMyQuery As QueryDef


i = DCount("*", qryname)
ReDim varArray(1 To i, 1 To 3) As Variant

Set db = CurrentDb
Set qdfMyQuery = db.QueryDefs("check register")
strSearchName = Forms![Check Register form]![Text2]
qdfMyQuery![Forms!Check Register form!Text2] = strSearchName


Set rst = qdfMyQuery.OpenRecordset()

For j = 1 To i
    varArray(j, 1) = rst.Fields(fldName).Value
    varArray(j, 2) = j
    varArray(j, 3) = fldName
    rst.MoveNext
Next
rst.Close
End If

If varArray(1, 3) & varArray(1, 1) <> (fldName & DLookup(fldName, qryname)) Then
    i = 0
    GoTo restart
End If

For k = 1 To i
If varArray(k, 1) = fldvalue Then
    QrySeq = varArray(k, 2)
    Exit Function
End If
Next

QrySeq_Exit:
Exit Function

QrySeq_Err:
MsgBox Err & " : " & Err.Description, , "QrySeqQ"
Resume QrySeq_Exit

End Function
 

Users who are viewing this thread

Back
Top Bottom