query to filter from textbox entry

P

p-rat

I have a query that I would like to filter based on an entry into a
textbox on form. The query is used in a combo box on the same form.

Example would be textbox1 = location. combobox2 = locationequipment

When someone enters Dallas into textbox1 I would like this to
automatically filter the recordset of query to only the equipment in
this location.

Would someone know how to do this?
 
D

DStegon via AccessMonster.com

in the code of the text box put code in the afterupdate event of the control
that would set the filter of the combobox and requery the combo box and the
setfocus and cause the combo to drop down teh new list for select or viewing.

text1 in this example is your city entry. I dont know what your table are
like so I just assumed you would have som id and names stuff, but you should
be able to get the idea.

Private Sub Text1_AfterUpdate()

If Len(Me.Text1) > 0 Then
Me.Combo3.RowSource = " SELECT Customers.CustomerID, Customers.
CompanyName, Customers.ContactName, Customers.City FROM Customers " & _
"WHERE Customers.City Like '" & Me.Text1 & "';"

Else
Me.Combo3.RowSource = " SELECT Customers.CustomerID, Customers.
CompanyName, Customers.ContactName, Customers.City FROM Customers;"

End If
Me.Combo3.Requery
Me.Combo3.SetFocus
Me.Combo3.Dropdown

End Sub
 
J

John W. Vinson

I have a query that I would like to filter based on an entry into a
textbox on form. The query is used in a combo box on the same form.

Example would be textbox1 = location. combobox2 = locationequipment

When someone enters Dallas into textbox1 I would like this to
automatically filter the recordset of query to only the equipment in
this location.

Would someone know how to do this?

I'd use a combo box in place of Textbox1 just to avoid the risk of a user
typing in "Dalles" or "Dalllas".

Base the second combo on a Query referencing

=Forms!yourformname!firstcontrolname

as a criterion to limit the equipment to equipment at that location, and
Requery the combo box in the afterupdate event of the first.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top