Solved

Combo boxes

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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.
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…
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…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

623 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