Combo box updating

  • Thread starter Thread starter Mike J
  • Start date Start date
M

Mike J

Two combo boxes on one form(both tied to the same
query):one shows the id and the other the last name. IIf
I use one to choose a record, how do I get the other to
update to reflect the current record?
 
Mike

Why use two? Do you have more than one column in your comboboxes? Can you
use a single combobox with both fields?

If you are using the combobox(es) solely to select a record to display in
the form, do you need to keep the ID/Person showing once the form's loaded?

If you must update comboboxB based on A's selection (and vice versa),
consider adding an event procedure to the AfterUpdate event of each
combobox, refreshing the other.

By the way, I know two John Smiths -- If I pick one of them, which ID# goes
in the other combobox?!
 
-----Original Message-----
Mike

Why use two? Do you have more than one column in your comboboxes? Can you
use a single combobox with both fields?

If you are using the combobox(es) solely to select a record to display in
the form, do you need to keep the ID/Person showing once the form's loaded?

If you must update comboboxB based on A's selection (and vice versa),
consider adding an event procedure to the AfterUpdate event of each
combobox, refreshing the other.

By the way, I know two John Smiths -- If I pick one of them, which ID# goes
in the other combobox?!

--
Good luck

Jeff Boyce
<Access MVP>

.
The only reason I use two is because I want one to be
sorted on the ID and the other last name. If I can ust
one and be able to sort by either way then...
Each john smith will have thier id on their card. And yes
it's a risk!

Refresh? How? Thanks for the feedback
 
Are the combo boxes bound (in which case they will automatically show the
value of the bound field in the current record) or unbound.

If they have the same query as RowSource, how are they sorted differently?

To make unbound combo boxes _match_, give each a two-column row source, with
both the ID and the Name (but you can set the column that you're only going
to use in code to a zero width so it isn't visible). Then in the AfterUpdate
event, check the other ComboBox -- if it's value is not already equal to the
column that corresponds to its displayed field, set it from that column in
the just updated Combo Box.

Question is, though, what are you doing with the values once they _are_
selected? Are you displaying the selected record in the Form?

Larry Linson
Microsoft Access MVP
 
Each combo box is bound but use different queries.
ComboBox1 uses query1 sorted by id#; the other uses a
query sorted by last name. When I choose an id with
combobox1 the record is displayed on the form but
combobox2 is not updated and vice versa. If I use
a "findrecord" control to find a record, both comboboxes
are no updated with the current id and lastname for that
record.
 
Assuming both your combos are bound to the ID column then once the record
has been found and displayed on the form the ID on the form will match the
bound value required in each combo. Hence in the forms current event you can
merely set each combo to the value of the ID.

cboLastName=ID
cboID=ID

HTH
Sam
 
Back
Top