Solved

Setting the value of a combo box

Posted on 2003-11-20
7
296 Views
Last Modified: 2010-05-01
I have a combo box (ListType) with the values:

ListType.additem ("1")
                              2
                              3
                              4
                              5
                              6

On_Load I want to set the value of the ComboBox

     ListType=3

then take the listindex of the combo box and set it equal to another combobox

     ListTypeF.ListIndex=ListType.ListIndex

How can I do this?

   - Marc
0
Comment
Question by:MarcGraff
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9788256
Do you mean something like this?

Private Sub Form_Load()
With ListType
    .AddItem "1"
    .AddItem "2"
    .AddItem "3"
    .AddItem "4"
    .AddItem "5"
    .AddItem "6"
End With

With ListTypeF
    .AddItem "1"
    .AddItem "2"
    .AddItem "3"
    .AddItem "4"
    .AddItem "5"
    .AddItem "6"
End With

ListType.ListIndex = 2 ' to set to #3

ListTypeF.ListIndex = ListType.ListIndex


End Sub
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9788263
or maybe:

Private Sub Form_Load()
With ListType
    .AddItem "1"
    .AddItem "2"
    .AddItem "3"
    .AddItem "4"
    .AddItem "5"
    .AddItem "6"
End With

ListType.Text = "3"

ListTypeF.Text = ListType.Text

End Sub
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 9788313
My appologies, ListTypeF contains

     ListTypeF.additem "Stuff"
                                   "dshgaljsh"

are all all words... This is why I am trying to use there listindex.

   - Marc
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:MarcGraff
ID: 9788334
also ListType may have diffrent numbers in diffrent circumstances therefore I can not say .listindex=3 because sometimes that will give me a "2" and other times a "6"

Sorry,
   - Marc
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 9788425
How about:


Private Sub Form_Load()
Dim i As Integer

With ListType
    .AddItem "1"
    .AddItem "2"
    .AddItem "3"
    .AddItem "4"
    .AddItem "5"
    .AddItem "6"
End With

With ListTypeF
    .AddItem "Item1"
    .AddItem "Item2"
    .AddItem "Item3"
    .AddItem "Item4"
    .AddItem "Item5"
    .AddItem "Item6"
End With

ListType.Text = "3"

For i = 0 To ListType.ListCount - 1
    If ListType.List(i) = ListType.Text Then
        Exit For
    End If
Next i

ListTypeF.ListIndex = i


End Sub
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 250 total points
ID: 9788449
You could also add this to the ListType's click event to have ListTypeF to change when listType is changed:

Private Sub ListType_Click()
Dim i As Integer
For i = 0 To ListType.ListCount - 1
    If ListType.List(i) = ListType.Text Then
        Exit For
    End If
Next i

ListTypeF.ListIndex = i
End Sub
0
 
LVL 1

Author Comment

by:MarcGraff
ID: 9788638
Sweet! Thanks so much!

   - Marc
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

939 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now