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!

MultiSelect List boxes values 1

Status
Not open for further replies.

Dave177

Programmer
Jan 9, 2005
165
GB
I have a list box [lstReports] on simple multi select and a text box that refers to it [txtNumber]. As a user selects reports the last selected number appears in the text box. However, if a user deselects a report (ie. presses it again) the number for that report appears in the text box. Is there away of stopping this from happening?

Would be greatful for any help
 
What events are you using on either the list box and/or the text box?
 
I think it's referencing fine

=[lstReports].[column](0)

It's just that it shows the value of the last item clicked on even when that item is being "deselected" and not selected.

 
You would have to put code in one of the events to state that you don't want it selected.

You still did not state what event is being used.
 
And what about this ?
=IIf([lstReports].Selected([lstReports].ListIndex), [lstReports].Column(0), " ")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,
That's much better - thanks alot.

However, it could be better. When an item is deselected its number no longer appears. However, you still don't get the number of the report that is selected - [txtNumber] is blank.

For example if I select reports 2 and 3 and then I decide to cancel report 3 I would click it again to deselect it. When I do this [txtNumber] goes blank but what would be better would be to have it showing "2" as this report is still selected.

Would this be possible?

Dave
 
hneal98,

Thanks for the reply but I think that it happens automatically - which ever report is clicked on in the list box, its number appears in the txt box. What sort of code did you have in mind?


David
 
Of course it happens automatic. That is what events are. They happen when you interact with something on the form. That is whay I asked which event(s) you were using. However, if PHV's solution works, great. :)
 
hneal98,

Sorry about the misunderstanding - am quite new to this. I have now tried the following:

Code:
Private Sub lstReports_AfterUpdate()
If [lstReports].Selected([lstReports].ListIndex) Then
[txtNumber].Value = [lstReports].Column(0)

    Else: [txtNumber].Value = " "
    End If
    
End Sub

This has the same effect as PHV's suggestion. It's effect is good but when an item is "deselected" the [txtNumber] value is blank NOT the value of the remaining item selected, which would be preferable

Do you have any suggestions?

David
 
why have you got the listbox in multiselect mode? your afterupdate event is just selecting the last item clicked?
why not turn off multiselect!
hth
steve
 
Ok basically I had been trying to use a multi select box for both selecting just one item and many items. I wanted to use a button to either:
a) If one item was selected, open up a form to edit the details for that item..or
b) If more than one item was selected, then open an Access Report with those items selected included in the Report's query.

I had been experiencing problems with this and posted thread702-1152984. Meanwhile I had thought about other ways to do this and experimented with using a text box for displaying single selections made in a multiselect list box. However, this is when I found the problem above regarding deselecting. Which is why I posted this thread. Now however thread702-1152984 has now been answered and all sorted (my thanks to TheAceMan1)
Am slowly learning!
But thank you for your help

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top