Store Access Criteria in a Global String

Ksabai

Registered User.
Local time
, 19:52
Joined
Jul 31, 2017
Messages
104
I want to store the below Form Criteria in a Global String
Like " * " & [Forms]![frmReports]![cmbCropYear] & " * "

When i store it returns nothing, request someone to help.
 
It's not really global if you are pinning it to a form. Thus modular.
If the form isn't open then it won't work.

You can either set the global var as a literal hard coded value in the form,
Val= "like '*smith*'"

but why do to needed it if the form is not open?
 
iam looking to use a single access query for different forms
 
tried "Like " * " & [Forms]![frmReports]![cmbCropYear] & " * ""
its not working
 
Why not simply store the year in a local table and include that table in your queries?
Also using a text value as a year isn't very efficient, you'd be better off storing it as a date and simply extracting the year portion in your queries.
 
i do understand, may be i don't know how to do it. What iam trying to do is Use a Single Query and a Report for Different forms. Iam able to open a Query with DoCmd.OpenQuery but DoCmd.OpenReport gives and unknown error.
 
sorry i didn't know whether to post here or there, let me remove it there.
 
if the form (frmReports) is open, and the combo box is filled, then the query should work.
are all these true?
and there are no spaces in around the asterisk in the criteria: "*"

if the query works, then the report aint far behind.
 
1. Like is used ONLY with strings
2. Like is used ONLY when you want to search for partial strings.
3. It doesn't make sense to use Like with a field that contains a Year in any case.
4. You CANNOT pass operands to a query so you couldn't pass this string into a query.

Your query should use a tempvar as Gasman suggested. Each form would populate the tempvar at some appropriate point. Then the query uses the = operand to compare to the tempvar.

Select ...
From ...
Where Somefield = yourtempvar;

I don't care for tempvars so I am not up on the syntax. That might have to be:

Where Somefield = yourtempvar.Value
 
A working example would be

Code:
((tblSubmitterClient.SubmitterID)=[TempVars]![SubmitterID])
 
Last edited:
I agree with Gasman about TempVars. It may be one of the best features ever added to Access.

TempVars are great for passing values to Query. It is the only way I would do it now.

I have started converting all my existing queries to use TempVars and remove all form reference.
 
I insert TempVar criteria into my queries when possible, as well. Great feature.
 

Users who are viewing this thread

Back
Top Bottom