"Noel Sant" <(E-Mail Removed)> wrote in message
news:r7Xve.7525$(E-Mail Removed)
> I've come back to Access VBA after a long time and find myself
> confused.
>
> I have a form with two combo boxes, each bound to a different table.
> The user should choose a record from one or the other. I also have a
> text box where I want to put the Description of the item chosen, from
> whichever table has been used.
>
> So I have a change event for each combo box.
General suggestion: don't use the combo box's Change event. Use the
AfterUpdate event. If the user types in the combo, rather than using
the mouse to select an item, the Change event fires for every keystroke.
That's not usually what you want.
> Surely, since the user
> has just chosen a field (the Name) in a record from the particular
> table, the whole of that record should be available?
No "surely" about it!
> How do I get at
> it? The form is bound to a different table and the text box is
> unbound.
>
> The fact is the Access object models confuse me - all I need is an
> example (I hope).
The data from the combo box's rowsource table/query is only available in
the combo box if it was selected as one of the columns of the combo. If
it was, then you can use the control's Column property to access it.
Consider this example:
Combo Box "cboMyCombo"
-------------------------------
Row Source: SELECT ItemID, ItemName, ItemDesc
FROM tblItems;
Column Count: 3
Bound Column: 1
Column Widths: 0"; 1", 2"
In code,
Me!cboMyCombo
returns the value of ItemID for the chosen item
Me!cboMyCombo.Column(0)
returns the ItemID for the chosen item, formatted as a string
Me!cboMyCombo.Column(1)
returns the ItemName for the chosen item, formatted as a string
Me!cboMyCombo.Column(2)
returns the ItemDesc for the chosen item, formatted as a string
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)