Solved

Combo boxes

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
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…
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…

758 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

16 Experts available now in Live!

Get 1:1 Help Now