Solved

Combo boxes

Posted on 1998-12-03
2
161 Views
Last Modified: 2010-05-03
My brain hurts... I want to populate a list/combo box with a bunch of values from a database, i.e a list of countries, which each have their own code ('FR' for France etc) and this code needs to stored in the record I'm currently editing. Is this possible using the intrinsic combo/list controls (The ItemData property only holds integers)? Whats the best way to do it? I do not want to use the DBList controls if possible.

Any suggestions welcomed.
0
Comment
Question by:mshire
2 Comments
 
LVL 3

Accepted Solution

by:
traygreen earned 50 total points
ID: 1448033
To display them both.....

do while not rs.eof
   cboCountries.AddItem rs!CountryCode & " - " & rs!Country
   rs.MoveNext
loop

Otherwise, keep a paralell array....
Private asCountryCodes() as string

Private Sub LoadCountries
   redim asCountryCodes(0)
   do while not rs.eof
      cboCountries.AddItem rs!Country
      asCountryCodes(Ubound(asCountryCodes)) = rs!CountryCode
      redim preserve asCountryCodes(Ubound(asCountryCodes) + 1)
      rs.MoveNext      
   loop
End Sub

Private Function GetCurrentCode() as String
   GetCurrentCode = asCountryCodes(cboCountries.ListIndex)
End Function
0
 
LVL 3

Expert Comment

by:jjmartin
ID: 1448034
Load the country names into the listbox, and load the country code into a parallel array.  Then when you want to save, you can access the corrosponding country code by the listbox index.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

820 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