473,667 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA Code - OpenRecordSet - Error [3061] too few parameters. Expected 1.

133 New Member
I am receiving error code [3061] too few parameters. Expected 1. I can't seem to find the issue. The error code occurs when on this line of code:

Expand|Select|Wrap|Line Numbers
  1. Set rstTemp = CurrentDb.OpenRecordset("sql_Approvers_to_MktPlacePOs")
  2.  
The entire code is as follows:


Expand|Select|Wrap|Line Numbers
  1. Private Sub Create_tbl_DistinctPOsApprovers()
  2.  
  3. On Error GoTo Err_Hndlr
  4.  
  5. strPO_TEMP = " "
  6. strApprover_Level_TEMP = " "
  7. strApprover_Username_TEMP = " "
  8. strApprover_Last_Name_TEMP = " "
  9. strApprover_First_Name_TEMP = " "
  10.  
  11.  
  12. 'Delete temporary table
  13. DoCmd.RunSQL "DROP TABLE tbl_DistinctPOsApprovers;"
  14.  
  15.  
  16. CurrentDb.Execute ("CREATE TABLE tbl_DistinctPOsApprovers(PO VARCHAR(14), Approver_Level numeric,  Approver_Username VARCHAR(20), Approver_Last_Name VARCHAR(30),  Approver_First_Name VARCHAR(30))")
  17.  
  18. 'Bind rstTemp to the temporary table
  19. Set rstTemp = CurrentDb.OpenRecordset("sql_Approvers_to_MktPlacePOs")
  20. Set rstSummary = CurrentDb.OpenRecordset("tbl_DistinctPOsApprovers")
  21.  
  22.  
  23. rstTemp.MoveFirst
  24.  
  25. Do While rstTemp.EOF = False
  26.     If rstTemp!PO <> strPO_TEMP Then
  27.                 strPO_TEMP = rstTemp!PO
  28.                 strApprover_Level_TEMP = rstTemp!Approver_Level
  29.                 strApprover_Username_TEMP = rstTemp!Approver_Username
  30.                 strApprover_Last_Name_TEMP = rstTemp!Approver_Last_Name
  31.                 strApprover_First_Name_TEMP = rstTemp!Approver_First_Name
  32.  
  33. '***        write record
  34.             rstSummary.AddNew
  35.                 rstSummary!PO = strPO_TEMP
  36.                 rstSummary!Approver_Level = strApprover_Level_TEMP
  37.                 rstSummary!Approver_Username = strApprover_Username_TEMP
  38.                 rstSummary!Approver_Last_Name = strApprover_Last_Name_TEMP
  39.                 rstSummary!Approver_First_Name = strApprover_First_Name_TEMP
  40.             rstSummary.Update
  41.  
  42. '                    Debug.Print Forms!F_PR_Status!txb_Start_Date; " "; Forms!F_PR_Status!txb_End_Date
  43.  
  44. '***  assign temp values
  45. '            strProductNumber_TEMP = rstTemp!ProductNumber
  46. '            strProductDescription_TEMP = rstTemp!ProductDescription
  47. '*** clear out fields
  48.  
  49.             strApprover_Level_TEMP = " "
  50.             strApprover_Username_TEMP = " "
  51.             strApprover_Last_Name_TEMP = " "
  52.             strApprover_First_Name_TEMP = " "
  53.  
  54.     End If
  55.  
  56.     rstTemp.MoveNext
  57. Loop
  58.  
  59.  
  60. rstTemp.Close
  61. rstSummary.Close
  62.  
  63. Create_tbl_DistinctPOsApprovers_Exit:
  64.   Exit Sub
  65.  
  66.  
  67. Err_Hndlr:
  68.     MsgBox "[" & Err.Number & "]:  " & Err.Description, vbInformation, "Create_tbl_DistinctPOsApprovers()"
  69. End Sub
  70.  
Sep 7 '10 #1
6 12409
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. There are two different types of recordset available in Access: Data Access Objects (the built-in recordsets in Access) and ActiveX Data Objects (ADOX). Unfortunately the two recordset types use different methods, and the error message you are getting on the Openrecordset method is typical if in fact an ADO recordset is implicitly declared when a DAO recordset type is being expected.

To overcome this you will need to qualify the declaration of your recordsets (which I do not see in the code you provided):

Expand|Select|Wrap|Line Numbers
  1. Dim rstTemp as DAO.Recordset
  2. Dim rstSummary as DAO.Recordset
To avoid compilation errors you must make sure you have a reference set to the MS DAO object library - from the VBA Editor select Tools, References and ensure that you have a tick under the Microsoft DAO 3.6 library (or its equivalent).

-Stewart
Sep 7 '10 #2
parodux
26 New Member
If you run sql_Approvers_t o_MktPlacePOs on its own then it will ask you about the criteria you have in the query. If you have something like: BETWEEN [forms]![YourForm]![DateFrom] AND [forms]![YourForm]![DateTo] then your solution would look like this:

Expand|Select|Wrap|Line Numbers
  1. Dim db as DAO.Database
  2. Dim qdf as DAO.Querydef
  3. Dim rstTemp as DAO.Recordset
  4. Set db = CurrentDb()
  5. Set qdf = db.QueryDefs("sql_Approvers_to_MktPlacePOs")
  6. qdf.Parameters(0) = Forms!YourForm!DateFrom
  7. qdf.Parameters(1) = Forms!YourForm!DatoTo
  8. Set rstTemp = qdf.OpenRecordset
  9.  
Sep 8 '10 #3
dowlingm815
133 New Member
Good morning,

The code declared both record sets as DAOs and the VBA Editor had select the Microsoft DAO 3.6 library (or its equivalent). And the issue still occurred.
Sep 8 '10 #4
Stewart Ross
2,545 Recognized Expert Moderator Specialist
please post the SQL for sql_Approvers_t o_MktPlacePOs, which is what is being opened as a recordset.

Please note that if you have a reference to a form control in the Where clause of the query this can cause the 'too few parameters' failure you mention.

-Stewart
Sep 8 '10 #5
dowlingm815
133 New Member
Yes, it was the form that was generating this error. thank you for your assistance. when it was declared, the error code went away....

i appreciate your help.
Sep 8 '10 #6
dowlingm815
133 New Member
I am receiving an error now "[3265]: Item not found in the collection" at the line below. The value of Forms!F_Waiver_ Yr!Txt_Waiver_Y r is 10.

Expand|Select|Wrap|Line Numbers
  1. qdf.Parameters(0) = Forms!F_Waiver_Yr!Txt_Waiver_Yr
  2.  
The code is as follows:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Create_tbl_DistinctPOsApprovers()
  2.  
  3. On Error GoTo Err_Hndlr
  4.  
  5.  
  6. Dim qdf As DAO.QueryDef
  7. Dim dbs As DAO.Database
  8. Dim rstTemp As DAO.Recordset
  9.  
  10. Set dbs = CurrentDb()
  11.  
  12.  
  13. ' when query are used with form parameters, they must be declared in procedures as follows:
  14.  
  15. Set qdf = dbs.QueryDefs("sql_Approvers_to_MktPlacePOs")
  16. qdf.Parameters(0) = Forms!F_Waiver_Yr!Txt_Waiver_Yr
  17. Set rstTemp = qdf.OpenRecordset
  18.  
  19.  
  20.  
  21. strPO_TEMP = " "
  22. strApprover_Level_TEMP = " "
  23. strApprover_Username_TEMP = " "
  24. strApprover_Last_Name_TEMP = " "
  25. strApprover_First_Name_TEMP = " "
  26.  
  27. '**** create output table
  28. 'Delete temporary table
  29. DoCmd.RunSQL "DROP TABLE tbl_DistinctPOsApprovers;"
  30.  
  31. 'Create temporary table
  32. CurrentDb.Execute ("CREATE TABLE tbl_DistinctPOsApprovers(PO VARCHAR(14), Approver_Level numeric,  Approver_Username VARCHAR(20), Approver_Last_Name VARCHAR(30),  Approver_First_Name VARCHAR(30))")
  33.  
  34. 'Bind rstTemp to the temporary table
  35. 'Set rstTemp = CurrentDb.OpenRecordset("tbl_BlankWaiver_Approvers")
  36.  
  37. Set rstSummary = CurrentDb.OpenRecordset("tbl_DistinctPOsApprovers")
  38.  
  39.  
  40. rstTemp.MoveFirst
  41.  
  42. Do While rstTemp.EOF = False
  43.     If rstTemp!PO <> strPO_TEMP Then
  44.                 strPO_TEMP = rstTemp!PO
  45.                 strApprover_Level_TEMP = rstTemp!Approver_Level
  46.                 strApprover_Username_TEMP = rstTemp!Approver_Username
  47.                 strApprover_Last_Name_TEMP = rstTemp!Approver_Last_Name
  48.                 strApprover_First_Name_TEMP = rstTemp!Approver_First_Name
  49.  
  50. '***        write record
  51.             rstSummary.AddNew
  52.                 rstSummary!PO = strPO_TEMP
  53.                 rstSummary!Approver_Level = strApprover_Level_TEMP
  54.                 rstSummary!Approver_Username = strApprover_Username_TEMP
  55.                 rstSummary!Approver_Last_Name = strApprover_Last_Name_TEMP
  56.                 rstSummary!Approver_First_Name = strApprover_First_Name_TEMP
  57.             rstSummary.Update
  58.  
  59. '                    Debug.Print Forms!F_PR_Status!txb_Start_Date; " "; Forms!F_PR_Status!txb_End_Date
  60.  
  61. '***  assign temp values
  62. '            strProductNumber_TEMP = rstTemp!ProductNumber
  63. '            strProductDescription_TEMP = rstTemp!ProductDescription
  64. '*** clear out fields
  65.  
  66.  
  67.             strApprover_Level_TEMP = " "
  68.             strApprover_Username_TEMP = " "
  69.             strApprover_Last_Name_TEMP = " "
  70.             strApprover_First_Name_TEMP = " "
  71.  
  72.  
  73.  
  74.     End If
  75.  
  76.     rstTemp.MoveNext
  77. Loop
  78.  
  79. '***        write last record
  80.  
  81.  
  82.  
  83. rstTemp.Close
  84. rstSummary.Close
  85.  
  86. Create_tbl_DistinctPOsApprovers_Exit:
  87.   Exit Sub
  88.  
  89.  
  90. Err_Hndlr:
  91.     MsgBox "[" & Err.Number & "]:  " & Err.Description, vbInformation, "Create_tbl_DistinctPOsApprovers()"
  92. End Sub
  93.  
  94.  
  95.  
Sep 10 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
9473
by: Dee | last post by:
Running an AfterUpdate event procedure, I get the following error: "Too few parameters. Expected 1." My code is as follows: Private Sub DealerID_AfterUpdate() Dim db As DAO.Database
0
3303
by: Miranda Evans | last post by:
I noticed several postings about issues related to "run-time error 3061", and I observed that the solutions to these issues appear to involve correcting something within the SQL code. I'm encountering the "run-time error 3061" issue, but I'm not sure how to go about correcting the SQL. My hunch is that I have not properly constructed things to identify a date field, but I don't know how to correct this issue. In addition to not...
2
5539
by: Steve Richfield | last post by:
There have been LOTS of postings about error 3061, but mine seems to be an even simpler case than the others. I have a simple **FUNCTIONING** query called qryEdits. Copying the SQL from the query, it reads: SELECT Edits.Pattern, Edits.From, Edits.To FROM Edits WHERE (((Edits.Language)=!.)); The idea is to select just the language-appropriate records from the
2
5934
by: fanfromfla | last post by:
I am using a database that has worked for many years for a holiday project for needy families. My organization recently upgraded its server and changed everyone to Windows XP. I just mention that in case that has anything to do with the problem. There are pre-set reports that can be run with this database. I am getting a Runtime Error 3061 with one of them. It says Too Few Parameters. Expected 1. I have tried to trouble-shoot, but am...
4
7161
by: Richard Hollenbeck | last post by:
I thought I was very specific in this SQL request. There is a form open with a selected record (and a corresponding "lngRecipeID" on that form. The table also has a field called "lngRecipeID". But I keep getting this error: Runtime Error 3061: Too Few Parameters expected 1. What should I be looking for to fix this? Here's my code so far: Private Sub cmdAddIngredientToRecipe_Click() Dim dbGetRecipeID As DAO.Database
1
22293
by: Richard Hollenbeck | last post by:
I wonder what I'm missing? I really feel like a retard because I've been screwing with some code for a very long time. I just must be missing something very simple. In the following example, I've stripped away everything that doesn't cause the error to make my question a little simpler. Here's the problem in its simplest form inside a report: Dim db As DAO.Database
1
1886
by: istya | last post by:
I am having a dumb day to day. Can anyone have a schufty at my code and see why I am getting the runtime error 3061? I'm working on 2000 if that helps at all. Dim dbs As DAO.Database Dim results As DAO.Recordset Set dbs = CurrentDb Set results = dbs.OpenRecordset("SELECT COUNT(*) FROM name_check;") MsgBox (results(0)) 'Set results = dbs.OpenRecordset("SELECT division FROM divisions WHERE station= """ + !! + """;")...
3
4382
by: phill86 | last post by:
Hi, I am trying to run the following query in a recordset and i get the following error message Runtime error 3061 - Too few parameters. Expected 1 i am using the following code
8
2982
Cintury
by: Cintury | last post by:
The problem is I have a function that I've created and stored in a module. I call it as an expression (e.g. total: Function(parameter)). I'm receiving the error 3061: too few parameters, expected 1. Now the query and database are already open so I'm not entirely sure of any connection strings I may need. I think part of the problem may be that the parameter I am using to call the function is part of the query. I am not sure how to come by this...
3
1808
by: tasawer | last post by:
Hi, I need to add a new record to table "ACC_Vehicle", with three pieces of information. When I activate the code, I get the error "Error 3061, Too few parameters Expected 1" ACCVehicleID is the Autonumber field. Reg is a required field. Your help is appreciated.
0
8458
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8366
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7391
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.