click on individual parts of list box selection

megatronixs

Registered User.
Local time
Today, 12:39
Joined
Aug 17, 2012
Messages
719
Hi all,

I was wondering if it is possible to click on individual parts of a list box selection.
In the below code, I run a query from a button that is on top of a list box row headers. Would it be possible to click on one of the columns and have the same effect? After several hours of google I got the below code, but I would like to avoid the buttons :-)
Code:
Private Sub btn_account_1_Click()
    Dim strCol4     As String
    Dim where       As String
strCol4 = ListSearch.Column(3)
    If strCol4 <> "" Then
        where = "WHERE account_no1 LIKE '*" & strCol4 & "*' OR account_no2 LIKE '*" & strCol4 & "*' OR account_no3 LIKE '*" & strCol4 & "*' " & _
        "OR account_no4 LIKE '*" & strCol4 & "*' OR account_no5 LIKE '*" & strCol4 & "*' "
    End If
    
Me.ListSearch.RowSource = Replace(BASE_SQL, "<whereclause>", where)
End Sub

Greetings.
 
You select a row with a listbox and can use the listbox after update event or mouse up event to run code such as you have in your button.

If it is always column 3 you are interested in then you can make this the bound column. Columns start from 0, bound starts from 1 so you would set the bound column to 4.

Otherwise, with regards selecting a particular column, the only way you could do it is to use the mouse up event - which will tell you where the mouse is over the listbox relative to the top left of the listbox. If you know the widths of the columns and heights of the rows, you can work out which column and row was clicked. Gets even more complicated if the listbox is scrollable.

In all honesty, better and significantly easier to use a continuous subform which has been formatted to present like a listbox. Then you can put events in each control
 
Hi CJ London,
yea, finally I went that way. I added the code to the click event in the cell of the data sheet and it does the trick. The cell then triggers the data appears in a list box that I have to show the sub data.

Always nice to have great people like you in this great forum :-)

Greetings.
 

Users who are viewing this thread

Back
Top Bottom