Formulation of a criteria for a query (1 Viewer)

duke217

Registered User.
Local time
Today, 14:19
Joined
Jan 23, 2018
Messages
17
Hi guys,

Creating a query in design view, I want to use the value of a particular text box in an open form.

So, I write something like this in the 'Criteria' row of the query design view:
Code:
[forms]![myForm].[TextBoxName]

So be it. It works.

Is there any possibility to tell the query to pick up the criteria from the currently open form instead of having to designate it by name?

My point is to be able to use the same query from two different forms, using of course values from text boxes which have the same name.

I hope I explain myself clearly enough... :confused:
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:19
Joined
Aug 30, 2003
Messages
36,125
Short version is no. One option is to take criteria out of the query and use this for forms/reports:

http://www.baldyweb.com/wherecondition.htm

another is to have a hidden form (or hidden textbox(es) on a form that stays open all the time). Your query gets the criteria from there, your 2 forms copy the value there before running the query.
 

plog

Banishment Pending
Local time
Today, 07:19
Joined
May 11, 2011
Messages
11,645
No. My advice is to create a report, base it on the query you are using without any criteria or parameters, then when the user clicks a button on the form to open the report it uses DoCmd.OpenReport (https://docs.microsoft.com/en-us/office/vba/api/access.docmd.openreport) to open the report while passing a filter string to the report to show just the records you want.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:19
Joined
May 7, 2009
Messages
19,236
you might want to use Tempvars as criteria to your Query, eg:
Code:
TempVars!tvTextBox

but, you need to add code to each Form's Current Event:
Code:
Private Sub Form_Current()
TempVars!tvTextBox = Me.TextboxNameOnForm.Value
End Sub
 

Users who are viewing this thread

Top Bottom