vba - Bind TextBox to ComboBox in Access -
i have access table looks this:
+------------+--------+--------+--------+-------+ | partnumber | thing1 | thing2 | thing3 | item1 | +------------+--------+--------+--------+-------+ | 123 | abc | xyz | asd | poi | | 456 | qwe | sdf | ert | lkj | | 789 | jkl | iop | yui | mnb | +------------+--------+--------+--------+-------+
i wish create ms access form combobox , textbox such:
basically, want able add/edit fields in table selecting field in combobox , setting value of field in textbox. only, however, want edit thing# fields in table. how create macro, or vba system, accomplish this?
here's example started, though should want add additional things validation checks , whatnot.
firstly form should bound table supplied makes easier update data in table. called table "tblthings" in example, whatever call should in record source property form:
next, create combobox , text field unbound controls (i.e. add them in controls in design ribbon).
for combobox, can either use wizard type values (options) want, or can skip wizard , edit combobox's properties manually so:
next, i'd add button allow commit edits current record, , perhaps couple of navigation buttons go next/previous record.
here's mock-up:
the tick button press when want commit put in textbox thing# field you've selected in combo box.
the "tick" button has following vba in on-click event:
private sub cmdapply_click() forms(frmthings).controls(me.cbofieldselect) = me.txtfieldvalue end sub
here's "next" button's vba move next record (again in on-click event):
private sub cmdnext_click() docmd.gotorecord , , acnext end sub
and "previous" button's vba move next record (again in on-click event):
private sub cmdprev_click() docmd.gotorecord , , acprevious end sub
so when use form, if you:
- select "thing" field want edit
- use text box give value selected thing field
- click "tick" button , value should go in selected thing field
in above example i've shown bound fields of form can see effect working (though don't need have these visible on form).
here's link example access file.
update - alternative using combo box change event
as per comments below, here's way change event of combo box put data in thing fields (eliminating need button pass data).
switching order of text box , combo box, you'd enter data in text box first:
then when select thing field combo box, data text box put in appropriate thing field selected:
for work put same vba had tick button before in change event of combo box (i've emptied text box afterwards make clear user new value required next field need input):
private sub cbogblfieldsselect_change() forms(frmthings).controls(me.cbogblfieldsselect) = me.txtgblfieldsvalue me.txtgblfieldsvalue = "" end sub
there's bit of validation in there locks combo box while text box empty.. may want remove/ignore in project if want allow use of nulls/zero-length strings.
Comments
Post a Comment