Search code examples
formsms-accessfilterkeyms-access-2010

MSACESS: Populating a new record with data from a pulldown bounded column


I was able to get my pulldown combo-box (cmb_users) to pull up records in a sub-form (contact_cards).

Now I want users to be able to add additional records in the sub-form but with the ID text box (txt_sc_owner_id)prepopulated with the sc_owner_id of the combo-box to tie the records together and keep the data relevant.

What is a clean way to auto populate a new record text box with the data from the pull-down. The target field in the sub-form is txt_sc_owner_id. I figure, the sloppy code would look something like this.

[Forms]![contact_cards]![txt_sc_owner_id] = [Forms]![user_forms]!cmb_users.column(0)

The challenge is when to instantiate this when the user starts populating a new record in the sub-form

enter image description here

Thanks.


Solution

  • You could set the DefaultValue of the textbox when updating the combobox:

    Private Sub YourCombobox_AfterUpdate()
    
        Me!NameOfTheSubformControl.Form!sc_owr_id.DefaultValue = """" & Me!YourCombobox.Value & """"
    
    End Sub