Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Textbox in query criteria question

Status
Not open for further replies.

HarryRagg

IS-IT--Management
Feb 2, 2006
2
US
Can a query use two different textboxes from two different forms in the criteria for one query field?

The database I am working in has three different tables.

Query1 is the recordsource for Form1 and Form1 has a textbox called Value1
There are also two other forms named Form2 and Form3
Form2 and Form3 both have a textbox named Value1

I want the ability to double click on either Value1 textboxes from either Form2 or Form3 and I'd like to pass that value to the criteria of Query1 and open Form1 filtered based on the value from one of the two textboxes.

My problem is if one of the two forms is closed, the query criteria can't find the textbox on the closed form.

Is there a way to "bypass" the part of the criteria that involves the texbox from the closed form or both forms if Form1 is the only form open?

I will do my best to clarify if anyone has any questions. Thanks!

 
from what you said i think you need the following code

if form1 and form2 are open

run X query

else

run Y query

end if

I have not got a clue how to code to see if a form is opened or not.... sorry, but i just thought this would clarify what you need..

And hopefully someone else can give you the code for this, good luck
 
i had a hard time putting this problem into words so I apologize. trying to simplifying things, if i have two forms, each of which have a textbox field, that when double clicked on, opens up the other form.
each query that feeds each form has criteria that references the other form.
so if i have Form1 open and I double click on the Value1 textbox, i need that value to feed into the query that is the recordsource for Form2 and then open Form2.
ok so here's the catch, I need it so that either form can be opened even if the other form is closed. therefore "bypassing" the part of the criteria in the query that looks for the textbox value.
does that make ANY sense??
I don't know if it would help if there was such a way to determine if a form was open because I think once the criteria expression was evaluated, the query would still bomb out once it couldn't find the refernced textbox because it was on a form that was not opened.
sorry that this is becoming convoluted....
 
unsure if this would help or not.. but have a 3rd form.

1st form, you double click and then it opens up form2.

But if the user just want to open up form2, instead you open up form3, looks the same, but does not reference to form1....

what values are you passing, if you only have 1 text box on a form, why can't you combine both together.... if you have a reason for creating it like this, if you could explain, because there may be a better way of achieving what you want....
 
Have a look at the 4th argument of the DoCmd.OpenForm method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

Or maybe create a general query to feed each form, and on double click of the text box, open the other form using a where clause or filtering criteria!

Private Sub TextBox1_DblClick(Cancel As Integer)
DoCmd.OpenForm "Form2",, "FilterField=" & Form1!TextBox1,
End Sub

Private Sub TextBox1_DblClick(Cancel As Integer)
DoCmd.OpenForm "Form1",, "FilterField=" & Form2!TextBox1,
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top