Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

How to pre-select items on a listbox?

  Asked By: Rose    Date: Mar 16    Category: MS Office    Views: 2020
  

I have a user form with 3 (single-select) listboxes, which are populated
out of 3 .csv files.
Basically, there is a CLient drop-down list, after you select it
there is a references list (based on client you picked), and there is
the users-assigned list(out of a global user list, does not depend on
client, and is loaded at the userform initialze)

It works fine, except that I would like to pre-select certain values
when I pick the client,
ie I pick client X, then sub-client is populated with X1, X2, X3, users
with U1,U2,U3.
I'd want say, X3 and U15 to be pre-selected when I pick client C12.

I thought of using listbox.listindex, but that only works at the
initialize event, and it doesn't help me here as I want to be able to
change clients without unloading the form.

Private Sub cmbClient_Change()
Dim Wholeline, s, str As String
s = """"
If Trim(cmbClient) <> "" Then
cmbRef.Clear
cmbRef.AddItem "None"
cc = cmbClient
Open references For Input Access Read As #3
While Not EOF(3)
Line Input #3, Wholeline
str = Trim(Replace(Wholeline, s, " "))
If getCname(str) = getCname(cc) Then cmbRef.AddItem
getReference(str)
Wend
Close #3
End If
End Sub

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Tara Ryan     Answered On: Mar 16

if you know the value of preselected item then use the likes of
Me.ListBox3.Value = "something"
or
Userform1.ListBox3.Value = "something"

 
Answer #2    Answered By: Sam Anderson     Answered On: Mar 16

the .value worked.

I have another question, reading off these .csv files  is quite slow,
do you know if I put them on a MS-access database would be any faster?

It would still need to go through it and match the names.

 
Answer #3    Answered By: Mehreen Malik     Answered On: Mar 16

If you used access  you could use parameterised queries. This might speed
things up a lot.

 
Didn't find what you were looking for? Find more on How to pre-select items on a listbox? Or get search suggestion and latest updates.




Tagged: