Need a command Button for 'Filter by selection'

A

AndreasO

How can I create this feature. The command button wizard doesn't give me the
option.
Can I use the code builder 'event procedure on click'? What is the SQL?
Thanks for your help.
Andreas
 
F

Francisco

AndreasO,

Here is some code that might give you a hint.

I am using Northwind for this example. I have a combo box with for the
region and I want to fill a List Box based on the selection made by the user.
I hope this help.

Private Sub cmdByRegion_Click()
Dim strSQL As String

strSQL = "SELECT LastName & ' ' & FirstName AS Name, Title " _
& "FROM Employees " _
& "WHERE Region = '" & cobRegion & "'"

lstEmployees.RowSource = strSQL

End Sub
 
D

Dirk Goldgar

AndreasO said:
How can I create this feature. The command button wizard doesn't give me
the
option.
Can I use the code builder 'event procedure on click'? What is the SQL?


If you really want to replicate the function of the right-click menu item
with a command button, you could create a command button with code like
this:

'----- start of example code -----
Private Sub cmdFilterBySelection_Click()

On Error Resume Next
Screen.PreviousControl.SetFocus
RunCommand acCmdFilterBySelection

End Sub
'----- end of example code -----

Of course, you must use the name of your own button in the name of the event
procedure.
 

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