Use VB to set a control value

E

EdSch

Hello.. I am currently using a "SetValue" macro to set the value of a control on a main form from a sub-form control. The main and sub forms are based on different tables, and the entry made in the sub-form needs to update the main-form. Currently my macro (using "SetValue") is as follows:

Item: [Forms]![MainForm]![Combo451]
Expression: [Forms]![MainForm]![SubForm].[Form]![cbohsup1

This works, however, I would like to eliminate the macro, and code it into the VB of the form, but as yet I have not been able to get the code right. Any suggestions would be welcome.

Thanks
 
T

Ted Allen

Try putting this in the afterupdate event of your combo
on the subform:

Me.parent.combo451 = Me.cbohsup1

HTH

-Ted Allen
-----Original Message-----
Hello.. I am currently using a "SetValue" macro to set
the value of a control on a main form from a sub-form
control. The main and sub forms are based on different
tables, and the entry made in the sub-form needs to
update the main-form. Currently my macro
(using "SetValue") is as follows:
Item: [Forms]![MainForm]![Combo451]
Expression: [Forms]![MainForm]![SubForm].[Form]! [cbohsup1]

This works, however, I would like to eliminate the
macro, and code it into the VB of the form, but as yet I
have not been able to get the code right. Any
suggestions would be welcome.
 
S

Sandra Daigle

Where is the code? If it is in the subform then since the 'me' keyword would
refer to the subform's form object you would say:

me.parent.combo451=me.cbohsup1

If the code is in the main form you would say:

me.combo451=me.subform.form.cbohsup1
 
J

John Vinson

Hello.. I am currently using a "SetValue" macro to set the value of a control on a main form from a sub-form control. The main and sub forms are based on different tables, and the entry made in the sub-form needs to update the main-form. Currently my macro (using "SetValue") is as follows:

Item: [Forms]![MainForm]![Combo451]
Expression: [Forms]![MainForm]![SubForm].[Form]![cbohsup1]

This works, however, I would like to eliminate the macro, and code it into the VB of the form, but as yet I have not been able to get the code right. Any suggestions would be welcome.

Thanks

If the VBA code is on the mainform, use:

Me!Combo451 = Me![Subform].Form!cbohsup1

If it's on the subform, use

Parent!Combo451 = Me!cbohsup1

In the first case note that [Subform] must be the name *of the Subform
control* on the main form - the box which contains the subform; this
name is not necessarily the same as the name of the form contained
within that control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top