Too Few Parameters error Expected 1

atrium

Registered User.
Local time
Tomorrow, 10:35
Joined
May 13, 2014
Messages
348
Whenever I try to run/execute a query/SQL from code which has a WHERE clause, I get a runtime errors , "Too Few Parameters. Expected 1."

Code:
     Dim strSQL As String
     Dim db As Database
     Dim RecCounter As Integer
     Dim rs As Recordset
     DBEngine.SetOption dbMaxLocksPerFile, 1000000
     Set db = CurrentDb
     strSQL = "SELECT * from APClientTasksToProcessQry WHERE ClientId = " & [Forms]![OpenClientTasksFrm]![ClientIdFld] & " ORDER BY APId, APStepId"
     Set rs = db.OpenRecordset(strSQL)
     RecCounter = 1
     Do While Not rs.EOF
        MsgBox "Record number " & RecCounter
        
        ' Deliver the precedent doc to create, create it and pick up the next task
        RecCounter = RecCounter + 1
        
        
        rs.MoveNext
      Loop
     rs.Close

I have dumbed the above code down. I just want to be able to loop through the records (at this point) but every time I introduce the 'where' I get the 'too few parameters error

In the immediate window delivers the goods
eg. SELECT * from APClientTasksToProcessQry WHERE ClientId = 1 ORDER BY APId, APStepId


ANY Ideas would be helpful

Would I be better to funnel the record set into this where I don't need the 'WHERE' statement.

Thanks

Atrium
 
It's probOh in the API query. Which you didn't show us.
 
Atrium,

The query APClientTasksToProcessQry probably doesn't have a column named ClientID.

Wayne
 
check if the fieldsnames are correct in your query, also qualify your fieldnames:

strSQL = "SELECT * from APClientTasksToProcessQry WHERE APClientTasksToProcessQry.ClientId = " & [Forms]![OpenClientTasksFrm]![ClientIdFld] & " ORDER BY APClientTasksToProcessQry.APId, APClientTasksToProcessQry.APStepId"
 
This is the query code

Code:
 SELECT APClientActionTasksQry.ActionTaskId, APClientActionTasksQry.APId, APClientActionTasksQry.Title, APClientActionTasksQry.APStepId, APClientActionTasksQry.APStepNumber, APClientActionTasksQry.StepDesc, APClientActionTasksQry.PrecDocId, APClientActionTasksQry.PrecDocCode, APClientActionTasksQry.Description, APClientActionTasksQry.ActionDueDate, APClientActionTasksQry.ClientId, APClientActionTasksQry.ClientShortFileNo, APClientActionTasksQry.ClientFileNumber, APClientActionTasksQry.FirstName, APClientActionTasksQry.MatterId, APClientActionTasksQry.UserId, APClientActionTasksQry.DateCreated, APClientActionTasksQry.Suppressed, APClientActionTasksQry.DateTaskCompleted, APClientActionTasksQry.Completed, APClientActionTasksQry.ProcessTask
FROM APClientActionTasksQry
WHERE (((APClientActionTasksQry.ClientId)=[Forms]![OpenClientTasksFrm]![ClientIdFld]))
ORDER BY APClientActionTasksQry.APId, APClientActionTasksQry.APStepId;



I have changed the strSQL to

Code:
      strSQL = "SELECT * from APClientTasksToProcessQry WHERE (((APClientActionTasksQry.ClientId)=[Forms]![OpenClientTasksFrm]![ClientIdFld])) ORDER BY APClientActionTasksQry.APId, APClientActionTasksQry.APStepId"

I took the above from the sql code of the query.

and still get the problem
 
strSQL = "SELECT * from APClientTasksToProcessQry WHERE APClientActionTasksQry.ClientId=" & [Forms]![OpenClientTasksFrm]![ClientIdFld] & " ORDER BY APClientActionTasksQry.APId, APClientActionTasksQry.APStepId;"
 
Thanks Arnelgp,

I have it working with the following

Code:
      strQryFile = "APClientActionTasksQry"
     Me.QryFile = strQryFile
     
     Set db = CurrentDb
     strSQL = "SELECT * FROM " & Me.QryFile & " WHERE ClientId = " & ClientIdFld & " ORDER BY APId, APStepId;"

Thank you for your help. Your solution was the same as mine but took into account the full derivative of the field.

:D Atrium
 

Users who are viewing this thread

Back
Top Bottom