formsms-accesstextboxms-access-2010subform

MS Access: How to use a pulldown combo-box control to populate multiple text fields in a form


There are 3 text fields that require population with column info from a combo-pull down.

enter image description here

The combo box control is called cmb_ao_owner(1), and the target text fields (to pass column data to) are txt_ao_owner_id(2), txt_ao_owner_phone(3), and txt_ao_owner_email(4) respectively.

The text fields are to be populated with column(1), column(2), and column(3) data respectively. The query from the combo box is:

SELECT [dbo_SUP_CONTACTS].[sc_owner_id], [dbo_SUP_CONTACTS].[sc_owner], 
[dbo_SUP_CONTACTS].[sc_work], [dbo_SUP_CONTACTS].[sc_email]
FROM dbo_SUP_CONTACTS ORDER BY [sc_owner]; 

The controls are in a sub-sub-form

parent-form: workbench
sub-form: contacts
sub-sub-form: asset_owners

..but I now know that it does not matter as the "Me" parameter I think addresses that.

Challenge I'm having is with the syntax to pass the combo data to the text fields in the same row after the update event.

FIG A: Attempt 1

Private Sub cmb_ao_owner_AfterUpdate()
me.parent.txt_ao_owner_id = [cmb_ao_owner].Column(2)
me.parent.txt_ao_owner_phone = [cmb_ao_owner].Column(3)
me.parent.txt_ao_owner_email = [cmb_ao_owner].Column(4)
End Sub

FIG A: Attempt 2

Private Sub cmb_ao_owner_AfterUpdate()    
Me!txt_ao_owner_id = Me!cmb_ao_owner.Column(2)
Me!txt_ao_owner_phone = Me!cmb_ao_owner.Column(3)
Me!txt_ao_owner_email = Me!cmb_ao_owner.Column(4)
End Sub

Each attempt yielded errors. Any suggestions? Any help is greatly appreciated.

Thanks.


Solution

  • Just tried this with a quick mock-up...

    Private Sub Combo0_AfterUpdate()
    Me.Text2.Value = Me.Combo0.Column(1)
    End Sub
    

    Shouldn't Me!txt_ao_owner_phone etc. in your examples also contain '.value' or '.text'? Therefore: Me!txt_ao_owner_phone.Value