PDA

View Full Version : Solved: Countries in a combobox



paddy69
12-28-2006, 02:55 AM
I have created a form on which people have to select in a combobox (cboCountry) their country of residence. To load all the countries that can be selected, I typed a lot of countries (AddItems) in the code. So my question is, is there an easier way to do this?

Furthermore I want to use the ISO country codes to compose a EmployeeCode (txtEmployeeCode). For example, if my EmployeeId (txtEmployeeId) is 9999 and I live in the Netherlands, my EmployeeCode would be NL9999. Is there a way I can bring the country code and the EmployeeId together based on the selection that is made in the cboCountry?

Bob Phillips
12-28-2006, 07:34 AM
This code shows a way of laoding the combobox with countries and codes and retrieving the selected code



Private Sub ComboBox1_Change()
With Me.ComboBox1
MsgBox .List(.ListIndex, 1)
End With
End Sub

Private Sub UserForm_Initialize()
Dim aryCountries, aryCodes
Dim i As Long

aryCountries = Array("England", "France", "Holland", "Germany") 'etc.
aryCodes = Array("GB", "FR", "NL", "DE") 'etc
With ComboBox1
For i = 0 To UBound(aryCountries)
.AddItem aryCountries(i)
.List(i, 1) = aryCodes(i)
Next i
End With

End Sub

fumei
12-31-2006, 07:12 PM
Is this for a school project?

fumei
12-31-2006, 07:21 PM
Sorry, forget that...I was think totally in another realm.

Find attached a demo. xld's post does not combine from a textbox. However, I used part of it.

Textbox (txtEmployeeID), and a combobox.

1. There is logic to the combobox that requires an input of the employee ID.

2. Further, the logic does error trapping on the input and will only accept numeric input. EmployeeID of "sdbkh" will be be accepted. If there is an error, a message is displayed and focus returned to txtEmployeeID textbox, and original input cleared.

3. If EmployeeID is numeric, then a Lable (NOT a textbox) is filled with the the ID and country code. Eg 9999 and NL. = NL9999

4. As you may want to change the ID, but NOT the country, if you want to do this, change the ID and click the Refresh button.

5. Load the userform by the keyboard shortcut: Alt-F

Bob Phillips
01-01-2007, 11:55 AM
... xld's post does not combine from a textbox.
Never said nor intimated that it did.


This code shows a way of laoding the combobox with countries and codes and retrieving the selected code.

fumei
01-02-2007, 06:18 AM
xld - Excuse me? Sorry, but I never stated that you DID say, or intimate, that. I never stated that you said or intimated anything.

I simply stated that it did not use a textbox, which the OP mentioned. So I posted something that did use a textbox. That is all. Sorry if you took that as some sort of criticism.