Solved

Setting the value of a combo box

Posted on 2003-11-20
7
306 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change the path of the data source in my Excel pivot table with macro 4 53
Excel - Save a copy of work book 13 91
VB6 - Convert HH:MM into Decimal 8 70
TT Auto Dashboard 13 101
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

756 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