| | | Jennifer K. |  |
| Posted: Tue Sep 09, 2008 12:03 pm Post subject: Selection Disappearing from Unbound Combo |  |
| |  | |
Confusing but please hang with me on this one!
I have an UNBOUND combo box of place names with associated town codes. There can be multiple place names that are associated with a specific single town. I originally had a combo box that listed the place names and the codes (with duplicates) such as:
Place_Na CTC_Code Town Addison 100 Addison Addison Village 100 Addison Old Addison Corners 100 Addison Addison Center 100 Addison
The table is supposed to store the CTC_code (100) but show the place name on the form. The problem with that was that if someone chose "Old Addison Corners" it would default to the top of the list "Addison" on the form even though it was storing the correct code in the table (100).
My solution was to create an UNBOUND combo box with just a list of place names:
Addison Addison Village Old Addison Corners Addison Center Bennington North Bennington
When I set up the combo box I asked it to store the value for later use.
I then created a BOUND text box for the code. In the UNBOUND combo box properties I created an event procedure on exit that would look up the code (CTC_Code) based on the chosen place (Place_Na) and return the CTC to the bound text box and thereby in the correct field (HCTC) in the table:
Private Sub PLACE_NA_Exit(Cancel As Integer) Dim ctc As Integer ctc = DLookup("[ctc_code]", "LOOKUP CTC Codes", "[PLACE_NA] = '" & [PLACE_NA] & "'") If (Not IsNull(ctc)) Then [HCTC].Value = ctc Else [HCTC].Value = 9999 End If End Sub
The current problem: After you leave the form the unbound combo box reverts to blank and is empty. Can it retain the selected place name?
Thanks, Jennifer |
|