?
Solved

Using a combo box

Posted on 2003-03-05
4
Medium Priority
?
163 Views
Last Modified: 2010-05-01
Hi...

   I have a combo box with a list of items in it and a textbox.
   The items in the combo box are:
9802
9402
2200
.
.
and so on..

  When 9802 is displayed in the combo box,I want an integer(let's say 1000) to appear on the textbox.And when 9402 is displayed,another integer should be displayed on the textbox.
  Should I make use of the index or wwhat???

Thanks


0
Comment
Question by:VivienW
[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
  • 2
4 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 8070956
No, make use of the .ItemData Property:

With Combo1
  .AddItem("9802")
  .ItemData(.NewIndex) = 1000
  .AddItem("9402")
  .ItemData(.NewIndex) = 2000
End With

Private Sub Combo1_Click()
  Text1.Text = CStr(Combo1.ItemData(Combo1.ListIndex))
End Sub
0
 
LVL 1

Accepted Solution

by:
Sanker earned 105 total points
ID: 8071400
Or just have:

Private Sub Combo1_Click()
select case combo1.text
 case is = "9802"
  text1 = "1000"
 case is = "9402"
  text1 = "a different integer"
end select
End Sub

Not as pretty as Tim's but alot simpler...
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 8071513
Simpler indeed, but often this info comes from a database so using the .ItemData property is more efficient.
0
 
LVL 1

Expert Comment

by:irfanazam
ID: 8086350
Using ItemData property is good. but the solution fails if the combo box items are sorted using Sort property. So be careful when sorting combobox items in the case you have attatched ItemData to Combo box item.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

762 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