Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 01-13-2016, 12:26 AM   #1
ccondran08
Newly Registered User
 
Join Date: Feb 2014
Posts: 58
Thanks: 12
Thanked 2 Times in 2 Posts
ccondran08 is on a distinguished road
Run-time Error '3061' Too Few Parameters. Expected 4.

Hi, looking for some help here please. I have a form that has a textbox in what I've called the "settings" tab of a control tab. The user can click on a button and edit the text box and type in an Activity Code that is then saved and used in a query to retrieve records that the user has selected (eg. [Forms]![frm_Main_Menu]![txtActivity1]).

The code below is used to export the query and paste it into a spreadsheet that is located in the directory of "TRACpath". During the execution of the code I get an Run-time error "3061" which appears and then the VBA editor appears and is highlighted on the following line ;

Set rs_Milestones = qdf_Milestones.OpenRecordset()

Can anyone please shed some light on this so I can get this finished...







Dim XL As Excel.Application
Dim xlWB As Workbook
Dim wbTarget As Workbook
Dim TRACpath As String


TRACpath = [Forms]![frm_Main_Menu].[txtTRAC_Path]



Dim qdf_Milestones As QueryDef
Dim rs_Milestones As Recordset

Set qdf_Milestones = CurrentDb.QueryDefs("qry_P3_Milestone_Gaps")
Set rs_Milestones = qdf_Milestones.OpenRecordset()

Set XL = CreateObject("Excel.Application")

Set wbTarget = XL.Workbooks.Open(TRACpath)


wbTarget.Worksheets("Data").Cells(2, 186).CopyFromRecordset rs_Milestones

wbTarget.Save
wbTarget.Close

Set wbTarget = Nothing
Set XL = Nothing
Set qdf_Milestones = Nothing

ccondran08 is offline   Reply With Quote
Old 01-13-2016, 01:07 AM   #2
Minty
AWF VIP
 
Minty's Avatar
 
Join Date: Jul 2013
Location: UK - Wiltshire
Posts: 5,436
Thanks: 128
Thanked 1,476 Times in 1,448 Posts
Minty has a spectacular aura about Minty has a spectacular aura about Minty has a spectacular aura about
Re: Run-time Error '3061' Too Few Parameters. Expected 4.

Is your query a crosstab query by any chance? If it is you have to define the parameters in the query design.
__________________
If we have helped please add to our reputation - click the scales symbol on the left, tick 'I approve' and leave a comment.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Minty is offline   Reply With Quote
Old 01-13-2016, 01:32 AM   #3
ccondran08
Newly Registered User
 
Join Date: Feb 2014
Posts: 58
Thanks: 12
Thanked 2 Times in 2 Posts
ccondran08 is on a distinguished road
Re: Run-time Error '3061' Too Few Parameters. Expected 4.

No, this isn't a cross tab query.

ccondran08 is offline   Reply With Quote
Old 01-13-2016, 02:53 AM   #4
Minty
AWF VIP
 
Minty's Avatar
 
Join Date: Jul 2013
Location: UK - Wiltshire
Posts: 5,436
Thanks: 128
Thanked 1,476 Times in 1,448 Posts
Minty has a spectacular aura about Minty has a spectacular aura about Minty has a spectacular aura about
Re: Run-time Error '3061' Too Few Parameters. Expected 4.

Could you post up the query - without it we are guessing.
__________________
If we have helped please add to our reputation - click the scales symbol on the left, tick 'I approve' and leave a comment.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Minty is offline   Reply With Quote
Old 01-13-2016, 05:19 PM   #5
ccondran08
Newly Registered User
 
Join Date: Feb 2014
Posts: 58
Thanks: 12
Thanked 2 Times in 2 Posts
ccondran08 is on a distinguished road
Re: Run-time Error '3061' Too Few Parameters. Expected 4.

This is a very simple query, it works fine when I open the query. The problem is when the code tries to grab the query and send it to the spreadsheet I am missing something that tells the query that there is a textbox on the form that is used to filter the query. I believe the answer is in the below link but for some reason I am missing something.


https://support.microsoft.com/en-us/kb/209203


SELECT tbl_P6_Data.[Activity Name], tbl_P6_Data.Finish, tbl_P6_Data.[Activity ID]
FROM tbl_P6_Data
WHERE ((tbl_P6_Data.[Activity ID])=Forms!frm_Main_Menu!txtActivity1);
ccondran08 is offline   Reply With Quote
Old 01-13-2016, 05:46 PM   #6
sneuberg
AWF VIP
 
Join Date: Oct 2014
Location: Tucson, Arizona
Posts: 3,493
Thanks: 359
Thanked 959 Times in 929 Posts
sneuberg will become famous soon enough sneuberg will become famous soon enough
Re: Run-time Error '3061' Too Few Parameters. Expected 4.

I suggest reading https://www.safaribooksonline.com/li...7/ch01s17.html

I am fairly certain the answer you need is there.

Added: Ok that is about the same info and in your link, still I do not see anything in your code like


qdfSample![Forms!FormName!ControlName] = _
Forms![FormName]![ControlName]



which is shown in your link.
__________________
And now nothing will be restrained from them, which they have imagined to do. Genesis 11:6

Steve

Last edited by sneuberg; 01-13-2016 at 05:52 PM. Reason: Acknowledged I did not have new info
sneuberg is offline   Reply With Quote
The Following User Says Thank You to sneuberg For This Useful Post:
ccondran08 (01-13-2016)
Old 01-13-2016, 09:47 PM   #7
ccondran08
Newly Registered User
 
Join Date: Feb 2014
Posts: 58
Thanks: 12
Thanked 2 Times in 2 Posts
ccondran08 is on a distinguished road
Re: Run-time Error '3061' Too Few Parameters. Expected 4.

Thanks sneuberg, the link you provided had my answer and you've saved my day. The full code is ;

Dim XL As Excel.Application
Dim xlApp As Excel.Application
Dim xlWB As Workbook
Dim wbTarget As Workbook
Dim TRACpath As String

Dim qdf_Milestones
Dim rs_Milestones


TRACpath = [Forms]![frm_Main_Menu].[txtTRAC_Path]


'Punch ETC Transfer
Set qdf_Milestones = CurrentDb.QueryDefs("qry_P3_Milestone_Gaps")

qdf_Milestones("Forms!frm_Main_Menu!txtActivity1") = Forms!frm_Main_Menu!txtActivity1
qdf_Milestones("Forms!frm_Main_Menu!txtActivity2") = Forms!frm_Main_Menu!txtActivity2
qdf_Milestones("Forms!frm_Main_Menu!txtActivity3") = Forms!frm_Main_Menu!txtActivity3
qdf_Milestones("Forms!frm_Main_Menu!txtActivity4") = Forms!frm_Main_Menu!txtActivity4


Set rs_Milestones = qdf_Milestones.OpenRecordset()

Set XL = CreateObject("Excel.Application")

Set wbTarget = XL.Workbooks.Open(TRACpath)


wbTarget.Worksheets("Data").Cells(2, 186).CopyFromRecordset rs_Milestones

wbTarget.Save
wbTarget.Close

Set wbTarget = Nothing
Set XL = Nothing
Set qdf_Milestones = Nothing


ccondran08 is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Run time error 3061. Too few parameters. Expected 2 solty89 Modules & VBA 3 10-23-2013 04:00 AM
Run-time error 3061 - Too few parameters. Expected 1 ria.arora Queries 6 12-23-2012 08:47 AM
Run time error 3061 too few parameters. expected 1 pengiliverpool VB.NET 0 08-05-2010 05:16 AM
Run-time error 3061 - Too few parameters. Expected 1 AndyCabbages Reports 4 06-06-2010 08:26 AM
Visual basic Run-time error '3061' Too few parameters, Expected 1 BobRoss Modules & VBA 8 05-08-2010 11:07 AM




All times are GMT -8. The time now is 04:55 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World