Solved

Combo boxes

Posted on 1998-12-03
2
159 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

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

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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

867 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

18 Experts available now in Live!

Get 1:1 Help Now