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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column in a Listbox

Status
Not open for further replies.

BeginnerProgrammer

Technical User
Aug 2, 2002
33
US
Can someone tell me if there is a way for Access to determine which column is clicked on in a single list box?

Thanks,
 
I bet someone has a better way but here is one way

in the listboxes mousedown event place this code
msgbox x

now run the form and click around between 1 and 2. Note the number that pops up the most when you are in column 2

change the code for the listboxes mousedown to
if x >= the number you noted then
msgbox column2
else
msbbox column1
end if

click around and see how accurate it is
of course it will require you to set the columns widths

to use it I would just set a public variable to the column value and go from there

for more then 2 colums use select case

 
Is there any way to do this on the onclick event. By using the mousedown event it gives me the info from the previous record and I need to get the info from the current record.


Thanks
 
no you can't read the mouse position in the on click event. But I don't see how it can be giving you the data from the previous record
if you click on a listbox item
the events occur in this order

MouseDown,MouseUp,beforeupdate,afterupdate,click

all in a matter of milliseconds(or seconds on this old system)

lets walk thru the code
Private Sub List6_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
intcolpos = X
End Sub
my public variable now is set to the position I just clicked
mouseup,and beforeupdate have occured now list0 is updated with the new selection

Private Sub List0_AfterUpdate()
If intcolpos > 1440 Then
MsgBox List0.Column(1)
Else
MsgBox List0.Column(0)
End If
End Sub

I ran this code for several tests and never once got the wrong value

perhaps if you post you code pr better explain what you are trying to do with the column



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top