VBA Code to copy value?

J

James

I have been working on a form that has a subform
displaying data from a query. I would like to click a
button and transfer the SSN on the main form to a selected
record in the subform.
I've used code to do the event procedure on a button on
the subform, only I do not know how to ID the main form in
the code to tell it where to pull the value from.

SSN.text = Text14.text

How do I code Text14's location on the main form?

Thanks!
 
M

Marshall Barton

James said:
I have been working on a form that has a subform
displaying data from a query. I would like to click a
button and transfer the SSN on the main form to a selected
record in the subform.
I've used code to do the event procedure on a button on
the subform, only I do not know how to ID the main form in
the code to tell it where to pull the value from.

SSN.text = Text14.text

How do I code Text14's location on the main form?

SSN.text = Me.Parent.Text14.text

But, why are you using the Text property?? Is your VB
background showing? ;-) In Access, the Text property is
only useful during data entry for the text box. You should
be using the Value property instead:

Me.SSN.Value = Me.Parent.Text14.Value

Since Value is the default property for controls, you do not
need to actually specify it.

Me.SSN = Me.Parent.Text14

is the usual way to write that assignment. Technically, the
Me object is not needed either, but using it will
disambiguate the control from a variable of the same name.
 

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