Run Time Error 3061 Too Few Parameters. Expected 3 (1 Viewer)

atrium

Registered User.
Local time
Tomorrow, 08:10
Joined
May 13, 2014
Messages
348
I am trying to read in a query file so I can do some work on each record (different work for each trans type) but I can't get to that point at the moment because I keep getting the above error.

I have checked all the fields in the query and they are the same name as on the table. The query that is being read is the result of a previous query that had external criteria).
The code is

Dim strQryFile As String
Dim strQryFileSql As String
Dim db As Database ' Should this line be Queries ??
Dim RecCounter As Integer
strQryFile = "DdSelectTransIntQry"

Dim rs As DAO.Recordset
Dim lUserID As Long
DBEngine.SetOption dbMaxLocksPerFile, 1000000
On Error GoTo ErrTrap
TaskCompletedFld = 0

Me.QryFile = strQryFile
lUserID = Me.UserIdFld.Value
Set db = CurrentDb
strQryFileSql = "SELECT * FROM " & Me.QryFile & ";"

All of the above variables have been declared properly

Any help would be most appreciated
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:10
Joined
May 7, 2009
Messages
19,227
is this what you have, your post have some html tags:
Code:
Dim strQryFile As String
Dim strQryFileSql As String
Dim db As DAO.Database ' Should this line be Queries ??
Dim RecCounter As Integer
strQryFile = "SelectTransIntQry"

Dim rs As DAO.Recordset
Dim lUserID As Long
DBEngine.SetOption dbMaxLocksPerFile, 1000000
On Error GoTo ErrTrap
TaskCompletedFld = 0

Me.QryFile = strQryFile
lUserID = Me.UserIdFld.Value
Set db = CurrentDb
strQryFileSql = "SELECT * FROM " &  Me.QryFile & ";"

do you have Parameter on your query that uses Form!Formname!tetxtboxname/comboname
 
Last edited:

Ranman256

Well-known member
Local time
Today, 18:10
Joined
Apr 9, 2015
Messages
4,339
if you have parameters in the query, like arnelgp says, a form object, forms!myForm!txtBox,
then you may need to use a queryDef to add the parameters

dim qdf as querydef
set qdf = currentdb.querydefs("query1")
qdf.parameters(0) = forms!myForm!txtBox
set rst = qdf.openrecordset()

Also, you can skip all this code and use a table that has the the item to select (Me.QryFile) and a query.
User picks the QryFile , and col2 has the query to run. Then the only code needed is:

docmd.openquery Me.QryFile.column(1)
'Note: in vb columns begin with zero.

no need to write code to capture the parameters, its all in the query.
tbl example
Kansas, qsGetKs
NY, qsGetNY
 

Users who are viewing this thread

Top Bottom