Need Help about Form and subform

M

March

Dear All,

I try to write VBA to display data from when I click a record in datasheet
subform to textbox in form. I try to write some code on On_current( ) event as

form.text1 = subform.text1


it doesn't work.

Please give me suggestion.

Thank you,

March
 
J

John W. Vinson

Dear All,

I try to write VBA to display data from when I click a record in datasheet
subform to textbox in form. I try to write some code on On_current( ) event as

form.text1 = subform.text1


it doesn't work.

Please give me suggestion.

Thank you,

March

The syntax for referring to a control on a subform is a bit peculiar. It does
not use the name of the Form object in the subform at all, instead it uses the
Name property *of the Subform control* on the mainform. To make matters even
more confusing, Access will often use the same name for both objects - the
container and the contents.

In code on the mainform use the Me! shortcut to refer to the current form:

Me!text1 = Me!subformcontrol.Form!text1

Note that this will pull the value of the currently selected subform record
(perhaps one of many) into the mainform. This is *probably* a bad idea; could
you explain why you feel that you need to do this?
 
Top