?
Solved

Using a combo box

Posted on 2003-03-05
4
Medium Priority
?
166 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

621 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