Form/Subform Combo Box

A

awach

I have a combo box with multiple columns in my form. I want to make the
control source of a field in the subform to be a column on the combo box in
the main form. What code do I use to call that?

Before I was using =ModelName.Column(1) but now how can I specify that it
is in the main form, not the subform?
 
B

Barry Gilbert

You can refer to the parent form like this:
Me.Parent.ModelName.Column(1)

However, I don't think you can use this as the control source. Control
Source indicates what field in a table or query the control is bound to. You
could use the Default Value property if the textbox is a bound control.

Barry
 
B

Barry Gilbert

Default Value indicates what to put in the control when starting a new record
in the subform. Is this what you want? If you want to change the subform
control's value from some event other than creating a new record, you'll need
to write a little code or a macro to fill the value.

Barry
 
A

awach

Isn't there another way to call the field without making it the default
value. I would like the default value to be 0 and then filled in when the
selection is made. Any ideas?
 
B

Barry Gilbert

If you want the subform' control's value to be filled when you select an item
in the parent's combobox, you can use the combobox's AfterUpdate event to
fill it with something like this:

Me.MySubformControl!Form.SubformTextbox = Me.ModelName.Column(1)

Again, it depends on the event you want to use to set the subform control's
value. Do you want to fill it after the combobox's value is changed? When a
new record is created in the subform? When the subform's control is clicked?
If you want this to happen in an event on the subform, you would need to
refer to the parent form's control, the way I suggested earlier.

Barry
 
A

awach

So, how can I do this if, after making the selection from the combo box 8
fields are supposed to be updated?

What would be the exact code if I want to update a field named [Cash]?

Thanks!
 
B

Barry Gilbert

Select the combobox. Click the elipsis to the right of the After Update
event. In the code editor, put:
Me.MySubformControl!Form.Cash = Me.ModelName.Column(1)

In this code, replace MySubformControl with the name of the subform control
in your parent form. This also assumes that column 1 (the second column)
contains the data you want to pass down.

You can replicate this for any subform control and any combobox column.

Barry
 
B

Barry Gilbert

Select the combobox. Click the elipsis to the right of the After Update
event. In the code editor, put:
Me.MySubformControl!Form.Cash = Me.ModelName.Column(1)

In this code, replace MySubformControl with the name of the subform control
in your parent form. This also assumes that column 1 (the second column)
contains the data you want to pass down.

You can replicate this for any subform control and any combobox column.

Barry
 
A

awach

What do you mean by subform control?

Barry Gilbert said:
Select the combobox. Click the elipsis to the right of the After Update
event. In the code editor, put:
Me.MySubformControl!Form.Cash = Me.ModelName.Column(1)

In this code, replace MySubformControl with the name of the subform control
in your parent form. This also assumes that column 1 (the second column)
contains the data you want to pass down.

You can replicate this for any subform control and any combobox column.

Barry

awach said:
So, how can I do this if, after making the selection from the combo box 8
fields are supposed to be updated?

What would be the exact code if I want to update a field named [Cash]?

Thanks!
 
B

Barry Gilbert

When you drop a form into another form, it is contained in a subform control.
A subform control has properties like Link Child Fields and Link Master
fields that link the parent form with the form contained by the subform
control. When you look at your parent form in design view, you know you have
the subform control selected when you see "Subform/Subreport" in the caption
(top bar) of the property sheet.

There are several topics in Access and VBA help on working with subforms and
how to reference controls. These would be a very worthwhile read for you.

Barry

awach said:
What do you mean by subform control?

Barry Gilbert said:
Select the combobox. Click the elipsis to the right of the After Update
event. In the code editor, put:
Me.MySubformControl!Form.Cash = Me.ModelName.Column(1)

In this code, replace MySubformControl with the name of the subform control
in your parent form. This also assumes that column 1 (the second column)
contains the data you want to pass down.

You can replicate this for any subform control and any combobox column.

Barry

awach said:
So, how can I do this if, after making the selection from the combo box 8
fields are supposed to be updated?

What would be the exact code if I want to update a field named [Cash]?

Thanks!
 
Top