Copy and paste from Main Form to Subform text boxes via code

ShovelinFishHeads

Registered User.
Local time
Today, 03:08
Joined
Aug 4, 2016
Messages
57
After reading through many threads here about copying and pasting via code and trying many examples of various strategies to do this, I need to get some advice. My attempts at this are not working.

I have mailing address information for "Carriers" and also for personnel of Carriers with a second table dedicated for personnel contact info. One-to-many relationship.

I want to allow for users to copy/paste, by way of a command button, the Carrier's "HQ" address into the employee's address when/if the employee doesn't use something different.

Forms are set up such that Carriers is one "main" form with Personnel in a subform under a tab strip control.

Currently trying to make this work:

Private Sub Command57_Click()

Dim strAddress1 As String

Forms![Carriers Main Form]!Address1 = strAddress1
strAddress1 = Forms![Carrier Personnel]!Address1

End Sub

Which results in => Run-time error '2450':

Microsoft Access cannot find the referenced form "Carrier Personnel".

Selected the subform (Carrier Personnel) by clicking on it one time while in design mode for the main (parent) form.

The property sheet says from the top: Selection type: Subform/Subreport; then the list box below that says "Carrier Personnel"

Link Master Fields shows CarrierID; Link Child Fields shows CarrierID; Filter On Empty Master shows Yes; Enabled shows Yes; Locked shows No.

Would love to get some feedback on why this isn't working; Or any advice.

Thanks everyone......
 
PMFJI,

I think the assignment should be the other way around?
My interpretation of the post is that the address will be copied from the main form to the subform?
 
stopher,

the code you suggested did have the significant effect of solving the Run-time error '2450':

Microsoft Access cannot find the referenced form "Carrier Personnel".

However, for some reason, the value was not pasted. And actually the value that was in 'Address1' on the main form was erased. So I have something very weird going on here. Maybe someone could explain why that could happen. I'm baffled by this.

I might have to change strategies and go with a check box for 'Employee uses the Corporate mailing address' and have the click event disable the Employee address fields on the Personnel form.
 
stopher,

the code you suggested did have the significant effect of solving the Run-time error '2450':

Microsoft Access cannot find the referenced form "Carrier Personnel".

However, for some reason, the value was not pasted. And actually the value that was in 'Address1' on the main form was erased. So I have something very weird going on here. Maybe someone could explain why that could happen. I'm baffled by this.

I might have to change strategies and go with a check box for 'Employee uses the Corporate mailing address' and have the click event disable the Employee address fields on the Personnel form.
like gasman said, the code I wrote was the wrong way round. Just reverse the references either side of the equals sign.
 
Ok. Which does explain why the value on the main form was changed to "nothing".

Thanks
 
After bench testing your code for Address1, Address2, City, StateID, and ZIP/Postal Code, it looks like its working perfectly. Just the way I wanted it.

THANKS!
 

Users who are viewing this thread

Back
Top Bottom