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

Listbox issue 1

Status
Not open for further replies.

skinicod

Programmer
Sep 9, 2003
46
GB
Hi,

I have a problem with a multi colum listbox. I want the user to be able to click on one of the items and then have various hidden column elements show up in captions on another part of the form.

This all sounds simple enough, however the problem I have is that the Click event does not seem to acknowledge the fact that I have selected a row. I create a row source for the listbox earlier in the program with the following code:

Mylist.RowSource = "SELECT table, name, value, count, uniqueobs, tab_percentage from audit" & Suffix & ";"

And my Click event looks like this:


Private Sub MyList_Click()
For Each varItm In Me.MyList.ItemsSelected
Info1.Caption = MyList.Column(0, varItm)
Info2.Caption = MyList.Column(1, varItm)
Info5.Caption = MyList.Column(4, varItm)
Next
End Sub


What is particularly annoying is that if I place the above code within a button object and click on the button after I have selected a row in my listbox, it works perfectly.

Intrestingly when viewing the form during debug mode all value disappear out of my listbox during the listbox Click event. I have therefore tried to restate the rowsource during the event, which has the effect of always selecting the first row within my listbox. The same thing happens if I refresh the database within the click event.

Any help/ideas would be gratefully received.

Skinicod
 
Hi!

You could try to use the listbox after update event.

Roy-Vidar
 
I tried that, but when i click on a row in the list box it doesn't go to the afterupdate event - don't know why...
 
Hi

Is this a multiselect list box?

If not why use the ItemsSelected property, why not simply use =MyList.Column(n) in the caption property of the labels

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Because I was unaware that you could do that...

Thanks that works perfectly, and you can rest in the knowledge that I am no longer ripping my hair out!
 
I have had the same problem as Skinicod trying to get Access to recognise that the user has made a selection in a list box.

My code is straight forward and like Skinicod I can get the code to work correctly by inserting it into the click event of a button instead.

My code is as follows:-

Dim ctlClub As Control
Set ctlClub = Me!ClubList

Dim intRow As Integer

For intRow = 0 To ctlClub.ListCount - 1
If ctlClub.Selected(intRow) Then
Me!ClubID = ctlClub.ItemData(intRow)
Me!VenueList.Requery
End If
Next intRow

Both the click event and the afterupdate event are triggered which I click in the listbox but neither seem to recognise that one of the lines has been selected (i.e. ctlClub.Selected(intRow) never seems to be true).

Ken's suggestion is a good one but I really don't want to go down the path of multiple selection as the user needs to select only one item.

Any suggestions.............?!

Many thanks!
 
KenReays suggestion is excellent when needing single selection (i e, the multiselect property is set to none), also just using

[tt]Me!ClubID = me!ClubList.value[/tt]

should work, under those circumstanses, if the value you're after, is in the bound column of the listbox control.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top