Access Error 3061 Expected 2
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more access vba error 3061 expected 1 about Stack Overflow the company Business Learn more about hiring developers or posting ads run time error 3061 expected 2 with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow
Error 3061 Too Few Parameters Expected 2
is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up VBA OpenRecordset Producing Too few parameters. Expected 2. Error up vote 4 down
Runtime Error 3061 Expected 1
vote favorite I have a query called qryAlloc_Source that has two paramaters under one criteria: >=[forms]![frmReportingMain]![txtAllocStart] And <=[forms]![frmReportingMain]![txtAllocEnd]) A have a separate query that ultimately references qryAlloc_Source (there are a couple queries in between), and that query runs fine when I double click it in the UI, but if I try to open it in VBA, I get an error. My code is: Dim rst As Recordset Set rst runtime error 3061 expected 3 = CurrentDb.OpenRecordset("qryAlloc_Debits") I am getting run-time error 3061, Too few parameters. Expected 2. I've read that I may need to build out the SQL in VBA using the form parameters, but it would be pretty complex SQL given that there are a few queries in the chain. Any suggestions as to a workaround? I considered using VBA to create a table from the query and then just referencing that table--I hate to make extra steps though. vba ms-access share|improve this question asked Jun 20 '14 at 21:41 rryanp 53541534 add a comment| 4 Answers 4 active oldest votes up vote 4 down vote accepted The reason you get the error when you just try to open the recordset is that your form is not open and when you try to access [forms]![frmReportingMain] it's null then you try to get a property on that null reference and things blow up. The OpenRecordset function has no way of poping up a dialog box to prompt for user inputs like the UI does if it gets this error. You can change your query to use parameters that are not bound to a form yourTableAllocStart >= pAllocStart and yourTableAllocEnd <= pAllocEnd Then you can use this function to get the reco
Search Community Links Social Groups Pictures & Albums Members List Calendar Search Forums Show Threads Show Posts Tag Search Advanced Search Find All Thanked Posts Go to Page... Page 1 of 2 1 2 >
Access Error 3061 Openrecordset
Thread Tools Rating: Display Modes 04-14-2003, 02:19 AM #1 Ally Newly Registered User ms access error 3061 Join Date: Sep 2001 Location: Colchester, Essex, England Posts: 617 Thanks: 0 Thanked 2 Times in 2 Posts Error 3061: Too run time error 3061 too few parameters expected 1 Few Parameters. Expected 2 I have a form, which is opened from another form. When I try doing anything on the second form, I get the error message: Run-time error ‘3061’: Too few parameters. Expected 2 The code http://stackoverflow.com/questions/24336077/vba-openrecordset-producing-too-few-parameters-expected-2-error that is running is: Code: Private Sub ACPDailyDate_Exit(Cancel As Integer) Dim x, y, z As String Dim r As Recordset, db As Database Dim DocName As String Dim LinkCriteria As String DocName = "frmACPData" Dim intNewRecord As Integer intNewRecord = IsNull(Me.ACPDailyID) Set db = CurrentDb() Set r = db.OpenRecordset("qryPtACPDaily") 'If intNewRecord Then Do Until r.EOF If r.Fields("acpdailydate") = Me.ACPDailyDate.Value Then msgbox r.Fields("PtFirstName") & " " & r.Fields ("PtLastName") & " already has ACP data for http://www.access-programmers.co.uk/forums/showthread.php?t=45940 this date " & _ Chr(13) & r.Fields("acpdailydate"), vbOKOnly + vbExclamation, "Warning" DoCmd.Close Exit Sub ElseIf r.NoMatch Then End If r.MoveNext Loop 'Else Exit Sub 'End If Me.Refresh Exit Sub End Sub The line highlighted is: Set r = db.OpenRecordset("qryPtACPDaily") In the query there are 2 parameters: [Forms]![frmACPData]![EpisodeID] [Forms]![frmACPData]![UnitNo] The query runs fine on its own (when the form’s open). Does anyone know what’s wrong please? __________________ If you want to go to Heaven, you have to go via King's Cross! Not sure what to do with your old photos, or would like a special gift! To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. - UK Last edited by Ally; 04-14-2003 at 02:22 AM. Ally View Public Profile Find More Posts by Ally 04-14-2003, 02:33 AM #2 Mile-O Back once again... Join Date: Dec 2002 Location: Glasgow, UK Posts: 11,312 Thanks: 4 Thanked 112 Times in 107 Posts It would look like you are opening the query (via DAO) when it requires the parameters to open the query and, if the form is not open, it can't get to them. Keep the form frmACPData open, or if you don't want to see it set its Visible property to NO (at least that way it
soon) Ruby (coming soon) Getting Started Code Samples Resources Patterns and Practices App Registration Tool Events Podcasts Training API Sandbox Videos Documentation Office Add-ins Office Add-in Availability Office Add-ins Changelog Microsoft Graph https://social.msdn.microsoft.com/Forums/office/en-US/556003a2-f970-4f6e-8bcc-9c8e73e25deb/run-time-error-3061-too-few-parameters-expected-2?forum=accessdev API Office 365 Connectors Office 365 REST APIs SharePoint Add-ins Office UI Fabric http://p2p.wrox.com/access-vba/30926-runtime-error-3061-too-few-parameters.html Submit to the Office Store All Documentation https://www.yammer.com/ http://feeds.feedburner.com/office/fmNx Ask a question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Answered by: Run time error 3061. Too few parameters. Expected 2. Microsoft Office for Developers > Access for Developers Question 0 Sign in to vote error 3061 It looks valid to me but for some reason I think I will need to change the syntax. Does anyone know what this should look like for Access 2007? Set rs = CurrentDb.OpenRecordset("select distinct report-period from Reports;") Wednesday, November 30, 2011 1:58 AM Reply | Quote Answers 1 Sign in to vote It looks valid to me but for some reason I think I will error 3061 expected need to change the syntax. Does anyone know what this should look like for Access 2007? Set rs = CurrentDb.OpenRecordset("select distinct report-period from Reports;") Is "report-period" the name of a field? If so, the fact that it contains "punctuation" -- in this case, what looks to Access like a minus sign -- means you have to enclose it in square brackets: Set rs = CurrentDb.OpenRecordset("select distinct [report-period] from Reports") Otherwise, Access thinks that "report" and "period" are identifiers, and if they aren't fields in the Reports table then it figures they must be parameters. Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html Marked as answer by S.e.p.y Wednesday, November 30, 2011 2:46 AM Wednesday, November 30, 2011 2:22 AM Reply | Quote Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. If you choose to participate, the online survey will be presented to you when you leave the Msdn Web site.Would you like to participate? Privacy statement Community Resources O365 Technical Network MSDN Forums UserVoice Stack Overflow Follow Us Twitter Facebook Office Dev Blog © 2016 Microsoft United States - English Terms of Use Trademarks Privacy Statement
Unanswered Topics Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA Runtime Error 3061 - too few parameters User Name Remember Me? Password Reminder Password Register Register | FAQ | Members List | Calendar | Today's Posts | Search Access VBA Discuss using VBA for Access programming. Search Forums Show Threads Show Posts Advanced Search Find All Thanked Posts Go to Page... Welcome to the p2p.wrox.com Forums. You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free . Page 1 of 2 1 2 > Thread Tools Display Modes #1 (permalink) June 28th, 2005, 08:24 AM Raymie_C Authorized User Join Date: Apr 2005 Location: , , . Posts: 10 Thanks: 0 Thanked 0 Times in 0 Posts Runtime Error 3061 - too few parameters I am hoping someone could help. I have a database which users will access to update the status and forecast of business objectives and sub-objectives on a monthly basis. The users will open the form which presents a parameter form based on a parameter query. The users will select the reporting month from a combobox which opens the reporting form (grouped by objective with the sub-objectives listed in a subdatasheet form for that specific month). This works perfectly by restricting the sub-objectives by the month. The users will then update the status and forecast of these sub-objectives. The problem arises when I go to export the status and forecasts of that specified month to a PowerPoint presentation (for reporting at our monthly management meetings) I am presented with "Error 3061 : Too few parameters.Expected 1". Sometimes this number is 2. and breaks on the line below. Set recStatus = dbStatus.OpenRecordset(strSQL, dbOpenDynaset) strSQL contains the code: strSQL = "SELECT * FROM qryEnablerLookup WHERE [fkMonthID]" & " = '" & Forms!frmCriteria!cboMonth & "';" I am at a total loss. When I go to debugging, the value being passed is correct (e.g. 1 for Jan etc). I'm certainly not the best at SQL and vba for that matter, therefore any help would be greatly appreciated. Thanx in advance P.S. I've attached the complete code for the export button below. Private Sub cmdExport_Click() Dim dbS