Solved

ListBox with MultiSelect

Posted on 2001-08-10
13
465 Views
Last Modified: 2012-08-13
I had a listbox (single select) containing user information (noUser, name, stats) and I was using a ComboBox containing user info (noUser, name). So by selecting the name in the combo, I was highlighting the user in my listbox with the following code:

Forms![listbox].value = Forms![Combo].value  'Easy

But now I've changed my Listbox (single select) for a Listbox multiSelect, and it doesn't work since the .value in multiselect is always Null.

Is there an easy way to do that? I know I could have my data out of the listbox with .column(0) instead of .value, but to highlight the row containing noUser = X... I can't figure that out.

Any help would be appreciated, thanks
Jeff

0
Comment
Question by:jeanfrancoismelancon
  • 4
  • 4
  • 4
  • +1
13 Comments
 
LVL 8

Expert Comment

by:dovholuk
ID: 6372907
if you are trying to highlight a particular row, use this syntax:

Forms!YourForm!YourListBox.Selected(IndexValue) = True

i usually create a subroutine such as FindIndexValue for the listbox that will loop through and determine the index number if you don't know it... know what i mean?

cheers.

dovholuk
0
 

Author Comment

by:jeanfrancoismelancon
ID: 6372966
This is what I wanted to know. So there's no subroutine to do this for me... I'll have to create one myself?
0
 
LVL 8

Expert Comment

by:dovholuk
ID: 6373000
there's not a good one that i know of. maybe someone else can inform you of an access builtin feature i'm not aware of.

i use a for next loop and compare the values to the desired value, then (using the for next variable) when i find a match i know what index to "select".

i've tried using such things like ...SomeListBox("SomeValueIWantToFind").index but i've never gotten it to work...

i'll poke around a bit though as i'm intrigued again...

dovholuk
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 8

Accepted Solution

by:
dovholuk earned 100 total points
ID: 6373034
sorry. i can't find a more suitable method... here's what i use:

Function FindIndexValue(ctrl As Control, ValueToFind As Variant) As Long
Dim i As Long

For i = 0 To ctrl.ListCount - 1
     If ctrl.ItemData(i) = ValueToFind Then
          FindIndexValue = i
          Exit Function
     End If
Next i
FindIndexValue = -1
End Function

dovholuk
0
 
LVL 6

Expert Comment

by:PsychoDazey
ID: 6373044
I have this subroutine that chooses one or more items depending on which check box you click on, I'm sure you could modify it to do what you need:
Dim i As Integer
Dim x As Integer
Dim strSearchFor As String
 x = 0
 If Me!Check4 = -1 Then
    strSearchFor = "CT"
 ElseIf Me!Check5 = -1 Then
    strSearchFor = "New York"
    For i = 1 To List1.ListCount - 1
        If List1.ItemData(x) = strSearchFor Then
            List1.Selected(x) = True
    'Exit For
        End If
        x = x + 1
    Next
End If
0
 

Author Comment

by:jeanfrancoismelancon
ID: 6373845
I tried your code, it works for what it is made for, but doesn't for what I need.

I want to make it highlight my row with the noUser I have, but as if I clicked on it in my listbox (so it would unselect every other rows, and become the "current value" of the multiselect listbox).
0
 

Author Comment

by:jeanfrancoismelancon
ID: 6373855
This is a listbox multiselect extended in Access 97.
0
 

Expert Comment

by:dcom
ID: 6373857
If the list box and the combo box contain the same data in the same order????? Give this a try.

Public OldValue as Long

Private Sub Combo_AfterUpdate()
  Me.ListBox.Selected(OldValue) = False
  Me.ListBox.Selected(Me.Combo.ListIndex) = True
  OldValue = Me.Combo.ListIndex
End Sub

The middle line is the actual highlighter.  The others are to un-highlight the previous value in the list.
0
 
LVL 6

Expert Comment

by:PsychoDazey
ID: 6373860
Hmmm... I would start by trying this in the after update for your combo box:
Dim i As Integer
Dim x As Integer
Dim strSearchFor As String
x = 0
   strSearchFor = Me.[ComboBoxName].Text
   For i = 1 To List1.ListCount - 1
       If List1.ItemData(x) = strSearchFor Then
           List1.Selected(x) = True
   'Exit For
       End If
       x = x + 1
   Next
End If
0
 

Author Comment

by:jeanfrancoismelancon
ID: 6373934
This works perfectly, I don't know why I said it didn't work... it works.

Thanks a lot
0
 
LVL 6

Expert Comment

by:PsychoDazey
ID: 6373942
Problem solved then...good work dovholuk (as usual).
0
 
LVL 8

Expert Comment

by:dovholuk
ID: 6374136
right on. glad to help.

props and thanks to you psycho. have you officially made kpro status? if so congrats...

dovholuk
0
 
LVL 6

Expert Comment

by:PsychoDazey
ID: 6374268
Yes, ihave.  I appreciate the congrats.  I actually learn alot from you as I go through the questions and read your postings.  Most of the time I realize I have been doing things the long way!  Thanks and keep up the good work.  Good luck to you also jean, I hope I can assist you in the future!
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question