Visual basic Run-time error '3061' Too few parameters, Expected 1 (1 Viewer)

BobRoss

New member
Local time
Yesterday, 22:24
Joined
May 8, 2010
Messages
4
I commented out lines in the codebuilder one by one to determine which were and weren't working, see comments in brackets below:

Code:
Private Sub ReportButton_Click()

    Dim varItem As Variant

        For Each varItem In Me.ReportList.ItemsSelected

            CurrentDb.Execute Me.ReportList.Column(2, varItem)    <This runs a  delete query and works.>
            CurrentDb.Execute  Me.ReportList.Column(3, varItem)    <This also runs a delete query  and works.>
            CurrentDb.Execute Me.ReportList.Column(4,  varItem)    <This runs an append query and DOES NOT work; its  highlighted in the code builder>
            CurrentDb.Execute  Me.ReportList.Column(5, varItem)    <This also runs an append query  and DOES NOT work; its highlighted in the code builder>
            DoCmd.OpenReport Me.ReportList.Column(6, varItem), acViewReport     <This opens a report and works.>

        Next varItem

End  Sub
I can run the append queries manually and they all work fine. The column references in the code are also matched correctly to the columns in the listbox.

So I guess you can't use CurrentDB.Execute to run append queries?

Thank you for any ideas of what may be wrong. Always appreciated.
 

HiTechCoach

Well-known member
Local time
Today, 00:24
Joined
Mar 6, 2006
Messages
4,357
I normally always use .Execute for action query. This includes appends.

The issue is that you can not use form references for parameters.

I use DAO to modify the QueryDef before the Execute.
 

BobRoss

New member
Local time
Yesterday, 22:24
Joined
May 8, 2010
Messages
4
Can you please walk me through "using DAO to modify the QueryDef"? Maybe an example of how you do this to run append queries from form references?

It's just strange that CurrentDB.Execute works with delete queries and not append queries.
 

HiTechCoach

Well-known member
Local time
Today, 00:24
Joined
Mar 6, 2006
Messages
4,357
Can you please walk me through "using DAO to modify the QueryDef"? Maybe an example of how you do this to run append queries from form references?

It's just strange that CurrentDB.Execute works with delete queries and not append queries.

do your delete queries have parameters that are form references?
 

BobRoss

New member
Local time
Yesterday, 22:24
Joined
May 8, 2010
Messages
4
No, so we know it has to do with form references.
 

BobRoss

New member
Local time
Yesterday, 22:24
Joined
May 8, 2010
Messages
4
Google is showing to wrap the form references in Eval()? Good idea bad idea?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:24
Joined
Sep 12, 2006
Messages
15,653
Funny, I had this issue a few days ago, and I've seen a similar post also in the last day or so.

Instead of using a form reference, you could store the value in a global variable, and get the query to read it from there. Then you dont get the problem.
 

LPurvis

AWF VIP
Local time
Today, 06:24
Joined
Jun 16, 2008
Messages
1,269
In a shocking departure from my standard brevity... I went on (and on) about the subject in general over the way at this thread.
The advantage of that thread is it has some links found by Brent - and his take on things (as he is an advocate of the Eval method).

In particular, I advocate the use of a replacement function (i.e. instead of explicitly using OpenRecordset).
An example of which (and its use) can be found here.

Fundamentally, there's no requirement to switch your parameters all out to make an Eval call.

Have a read - see what you think.

Cheers.
 

Users who are viewing this thread

Top Bottom