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.
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.
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.
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.
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.?
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
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.