2
votes

I have two sets of code, that are the same I just change variables to another set that exist and now with the ones I changed I get an error saying "Run-time error '3061': Too few parameters. Expected 6."

This is the changed code:

  Dim rec As Recordset
    Dim db As Database
    Dim X As Variant
    Set db = CurrentDb
    Set rec = db.OpenRecordset("UnitMoreInfoQ")
    Const msgTitle As String = "Open Explorer"
    Const cExplorerPath As String = "C:\WINDOWS\EXPLORER.EXE"
    Const cExplorerSwitches As String = " /n,/e"
    cFilePath = rec("ProjFilePath")

It highlights this line:

Set rec = db.OpenRecordset("UnitMoreInfoQ")

This is the first code:

Dim rec As Recordset
Dim db As Database
Dim X As Variant
Set db = CurrentDb
Set rec = db.OpenRecordset("ProjectMoreInfoQ")
Const msgTitle As String = "Open Explorer"
Const cExplorerPath As String = "C:\WINDOWS\EXPLORER.EXE"
Const cExplorerSwitches As String = " /n,/e"
cFilePath = rec("ProjFilePath")

As you can see, the line has the same amount of parameters:

Set rec = db.OpenRecordset("ProjectMoreInfoQ")

This has gotten me quite confused for awhile because of this. How do I fix this error?

3
where does this UnitMoreInfoQ is defined?Jorge Campos
It's a query, that is started when you open the form the button that this code is in is on. This query has a column named "ProjFilePath". This column has the file location such as C:\TestD347HxD
Does UnitMoreInfoQ have some parameters?Jorge Campos
According to when I right click and go to parameters, unless that is not how you find out if it has parameters... no.D347HxD

3 Answers

2
votes

I didn't get the same result as you when testing your db, and I still don't understand the difference. However, maybe we can still get you something which works in spite of my confusion.

The query contains 6 references to form controls, such as [Forms]![WorkOrderDatabaseF]![Text71]. Although you're certain that form is open in Form View when you hit the "too few parameters" error at db.OpenRecordset("UnitMoreInfoQ"), Access doesn't retrieve the values and expects you to supply them.

So revise the code to supply those parameter values.

Dim rec As DAO.Recordset
Dim db As DAO.database
Dim prm As DAO.Parameter
Dim qdf As DAO.QueryDef
Dim X As Variant
Set db = CurrentDb
'Set rec = db.OpenRecordset("UnitMoreInfoQ")
Set qdf = db.QueryDefs("UnitMoreInfoQ")
For Each prm In qdf.Parameters
    prm.value = Eval(prm.Name)
Next
Set rec = qdf.OpenRecordset(dbOpenDynaset) ' adjust options as needed

I'm leaving the remainder of this original answer below in case it may be useful for anyone else trying to work through a similar problem. But my best guess is this code change will get you what you want, and it should work if that form is open in Form View.


Run this statement in the Immediate window. (You can use Ctrl+g to open the Immediate window.)

DoCmd.OpenQuery "UnitMoreInfoQ"

When Access opens the query, it will ask you to supply a value for the first parameter it identifies. The name of that parameter is included in the parameter input dialog. It will ask for values for each of the parameters.

Compare those "parameter names" to your query's SQL. Generally something is misspelled.


Using the copy of your db, DoCmd.OpenQuery("UnitMoreInfoQ") asks me for 6 parameters.

Here is what I see in the Immediate window:

? CurrentDb.QueryDefs("UnitMoreInfoQ").Parameters.Count
 6 

for each prm in CurrentDb.QueryDefs("UnitMoreInfoQ").Parameters : _
? prm.name : next
[Forms]![WorkOrderDatabaseF]![Text71]
[Forms]![WorkOrderDatabaseF]![ClientNameTxt]
[Forms]![WorkOrderDatabaseF]![WorkOrderNumberTxt]
[Forms]![WorkOrderDatabaseF]![TrakwareNumberTxt]
[Forms]![WorkOrderDatabaseF]![WorkOrderCompleteChkBx]
[Forms]![WorkOrderDatabaseF]![WorkOrderDueDateTxt]

Make sure there is a form named WorkOrderDatabaseF open in Form View when you run this code:

Set rec = db.OpenRecordset("UnitMoreInfoQ")
1
votes

Does the [UnitMoreInfoQ] query execute properly on its own? If you mistype a field in access it will treat that field as a parameter.

0
votes

ProjectMoreInfoQ and UnitMoreInfoQ are different queries... it sounds like one takes 6 parameters and the other doesn't. Look at the queries in Access and see if either have parameters defined.