Solved

ListBox with MultiSelect

Posted on 2001-08-10
13
467 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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