Filter Listbox using a combobox

S

Shawn

I have a database with two tables users and managers, which have a
relationship based on the manager_lname field. I created a form where
a user can select a manager's name from a dropdown (combobox) and it
would filter the data in the listbox. The data from the list box comes
from the users table. The problem is that when the manager's name is
selected a box appears stating "Enter Parameter Value". When I enter
the manager's name in to the box the filter works. I would like it to
filter as soon as a name is selected from the dropdown. In the
dropdown event I enter the following code to handle the filter.

Private Sub Combo2_AfterUpdate()

Dim strsql

Me.Combo2.SetFocus

strsql = "Select * from users"
strsql = strsql & " WHERE manager_last=" & Me.Combo2

Me.List6.RowSource = strsql

End Sub

Any help provided would be appreciated.
 
D

David Lloyd

Shawn:

If the managers name is a text field, your WHERE clause needs to be have
quotes. For example:

WHERE manager_last='" & Me.Combo2 & "'"


--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I have a database with two tables users and managers, which have a
relationship based on the manager_lname field. I created a form where
a user can select a manager's name from a dropdown (combobox) and it
would filter the data in the listbox. The data from the list box comes
from the users table. The problem is that when the manager's name is
selected a box appears stating "Enter Parameter Value". When I enter
the manager's name in to the box the filter works. I would like it to
filter as soon as a name is selected from the dropdown. In the
dropdown event I enter the following code to handle the filter.

Private Sub Combo2_AfterUpdate()

Dim strsql

Me.Combo2.SetFocus

strsql = "Select * from users"
strsql = strsql & " WHERE manager_last=" & Me.Combo2

Me.List6.RowSource = strsql

End Sub

Any help provided would be appreciated.
 
S

Shawn

That plus adding single quotes helped, so now it reads as seen below.
I also narrowed the fields I wanted. Thanks.

Private Sub Combo2_AfterUpdate()


strSQL = "Select USERID, GEID, FIRSTNAME, MIDDLENAME, LASTNAME, "
strSQL = strSQL & "GROUPID, REGIONNAME, RoleName FROM users "
strSQL = strSQL & "Where manager_last = ' " & Me.Combo2 & " ' "

Me!List6.RowSourceType = "Table/Query"
Me!List6.RowSource = strSQL


End Sub
 

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