Question : Access 2007 Combo box synchronization

i have a table in access 2007 with 2 fields (named tblnomoi).one field has the Municipalities (named dhmoi) and the other field has the counties. (named nomoi ).No primary key is set
i have built a form with 2 combo boxes named cbodhmoi and cbonomoi . I want every time i select a municipality from the cbodhmoi  combo box to automatically see at the second combo box ( cbonomoi) the county that this municipality belongs to.
It seems that the combo boxes are synchronized when i press the right arrow of the keyboard but i want the second combo box to automatically get synchronized without pressing any key .I also dont want the value in the combo box to be inserted to the table tblnomoi when a key is pressed from the keyboard.
Can you help me please ?

Thank you very much !
Attachments:
 
Database File
 

Answer : Access 2007 Combo box synchronization

In your cbohmoi combo, make sure to include BOTH fields from the table in your RowSource. You can hide the second one (the one showing the County) by setting ColumnCount=2 and ColumnWidths=0;1. The RowSource for your cbonomoi combo would be ONLY the County field from your table.

Now, in the AfterUpdate event of cbohmoi:

Sub cbodhmoi_AfterUpdate
  Me.cbonomoi = Me.cbohmoi.Columns(1)
End Sub

Note that Columns is zero-based, so the code above refers to the 2nd column in cbohmoi.

<I also dont want the value in the combo box to be inserted to the table tblnomoi when a key is pressed from the keyboard>

Then don't "bind" that combo to anything - set the ControlSource to an empty string. If you do that, you'll also have to include code such as shown above in the Form's Current event, which fires every time the user changes to a different record in that form.
Random Solutions  
 
programming4us programming4us