Too few paramaters. Expected 2 in OpenRecordset (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 17:01
Joined
Sep 21, 2011
Messages
14,365
I think post #12 explained your issue?
 

Timax

Registered User.
Local time
Today, 09:01
Joined
May 14, 2015
Messages
33
I think post #15 (Use TempVars) is more close to the real solution. Thank you Sir!
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 02:01
Joined
Jan 20, 2009
Messages
12,853
I think post #15 (Use TempVars) is more close to the real solution. Thank you Sir!

:(
When someone with Paul's knowledge and experience suggests something and you can't get it to work then you should suspect your implementation of it rather than the advice.

The Eval() parameter is a string. I expect you neglected to include the quotes around the reference to the control.

Code:
Eval("Forms!formname!controlname")
TempVars is another solution, but a very clumsy one. It means your queries cannot be run without using VBA to set the TempVars.
The Eval() solution works for both opening the query directly as well as sending it to OpenRecordset.

TempVars have always been a solution looking for a problem but there is always a better way.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:01
Joined
Aug 30, 2003
Messages
36,127
TempVars have always been a solution looking for a problem but there is always a better way.

It's good to know I'm not the only one that hasn't found a use for TempVars. Figured maybe I just was an old dog who couldn't figure out a new trick.

I suspect you're right about why Eval() didn't work for Timax. Those posts all happened in the middle of the night for me, so I didn't bother to follow up when I saw an alternate solution had been found.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:01
Joined
Sep 21, 2011
Messages
14,365
Galaxiom,

How would one run a query that could be used from several forms/reports not using tempvars?

Or is that just bad design.?

:(
TempVars have always been a solution looking for a problem but there is always a better way.
 

isladogs

MVP / VIP
Local time
Today, 17:01
Joined
Jan 14, 2017
Messages
18,247
I also never use tempvars.

As an alternative, you can use a public variable and a function
e.g. Set strCriteria= Me.controlname on a form
Have a module function GetCriteria and set it = strCriteria
Then use GetCriteria in the query criteria

This idea can be used endlessly throughout your application.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:01
Joined
Sep 21, 2011
Messages
14,365
Colin,

I feel I am missing something completely here.:banghead:

Surely that still involves VBA.
Is not a Tempvar just a permanent public variable.?


I also never use tempvars.

As an alternative, you can use a public variable and a function
e.g. Set strCriteria= Me.controlname on a form
Have a module function GetCriteria and set it = strCriteria
Then use GetCriteria in the query criteria

This idea can be used endlessly throughout your application.
 

isladogs

MVP / VIP
Local time
Today, 17:01
Joined
Jan 14, 2017
Messages
18,247
Colin,

I feel I am missing something completely here.:banghead:

Surely that still involves VBA.
Is not a Tempvar just a permanent public variable.?

Well technically it's like a temporary public variable.

Yes it involves using VBA. Where does this thread say no VBA allowed?
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:01
Joined
Sep 21, 2011
Messages
14,365
Post 23 says that approach is clumsy as it uses VBA, not that it is not allowed.?
So I was trying to think of how to do the same without using VBA, but not limited to a form control.?


Well technically it's like a temporary public variable.

Yes it involves using VBA. Where does this thread say no VBA allowed?
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 02:01
Joined
Jan 20, 2009
Messages
12,853
Well technically it's like a temporary public variable.

No, technically it is less temporary than any VBA variable. The name never made any sense to me.

TempVars is a Collection with a scope of the Project and is immune from being reset within the session.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 02:01
Joined
Jan 20, 2009
Messages
12,853
Post 23 says that approach is clumsy as it uses VBA, not that it is not allowed.?

What I said was that the query could not be run without setting the TempVar. The Eval solution doesn't require any VBA to run the query directly.
 

isladogs

MVP / VIP
Local time
Today, 17:01
Joined
Jan 14, 2017
Messages
18,247
True that. The name never made sense to me either.

Years ago I was tempted to use them by the fact that unlike public variables, supposedly the value of tempvars couldn't get 'lost' after a program error.
I soon found out that wasn't always true and gave up on them.

Well written code and good error handling are IMO a better approach
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 02:01
Joined
Jan 20, 2009
Messages
12,853
How would one run a query that could be used from several forms/reports not using tempvars?

The easiest way to centrally persist a readily accessible value for the whole session is to store it in a form with a default value expression. The form can be hidden.

Another alternative is a Public variable with a wrapper function as Colin suggested. Much like using Eval() but you have to set the variable once with VBA.

Pass the parameters to the QueryDef before you Open it.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:01
Joined
Sep 21, 2011
Messages
14,365
What I said was that the query could not be run without setting the TempVar. The Eval solution doesn't require any VBA to run the query directly.

OK, finally got it.:banghead:

Had to actually recreate the scenario to understand it all.

Thank you.
 

Users who are viewing this thread

Top Bottom