I need to develop a way to copy contents from one sub-form to another subform.

I need to develop a way to copy contents from one sub-form to another sub-form.  I have three sub-forms on a main form.  The three are next to each other left-to-right.  The two left-hand sub-forms are bound to tables and the data being shown is locked.  The right-hand sub-form is bound to a table also but think of it as a new record that is being created.  If I double click one of the fields shown in one of the two left-hand sub-forms, I want that data to be copied over to the right-hand sub-form.

Actually, if I could click and drag the contents from one of the two left-hand sub-forms I would but I'm not sure that's possible, correct?  So I'm opting for the double-click method instead.

What would the VBA code look like to accomplish this?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteveL13Author Commented:
Additional comment. When I d-c on the field I need that fields content copied as well a hidden fields content in the same record copied.
SteveL13Author Commented:
Into 2 fields.
You'd run an INSERT query through the dblClick event:

Dim s As string
s = "INSERT INTO tblB (MyNumber, MyString) VALUES (" & me.MyNumericField & "," & chr(34) & me.MyTextField & chr(34) & ")"
currentdb.execute s, dbfailonerror

Open in new window

The Five Tenets of the Most Secure Backup

Data loss can hit a business in any number of ways. In reality, companies should expect to lose data at some point. The challenge is having a plan to recover from such an event.

SteveL13Author Commented:
This has changed.  Sorry about that.  I now have 4 text fields that need to be entered in the table.  Here is my code:

s = "INSERT INTO tblFoundation (MyStringA, MyStringB, MyStringC, MyStringD) VALUES (" & Forms!frmProjectBuilder.txtCategory & "," & Chr(34) & Me.txtSubCategory & "," & Chr(34) & Forms!frmProjectBuilder.txtJobNumber & "," & Chr(34) & Me.txtDescription & Chr(34) & ")"

Open in new window

But I am getting error:  Syntax error (missing operator) in query expression "Underslab Insulation, "Z999'!

All four fields are text so I have:
SteveL13Author Commented:
And when I Debug.Print I get:

INSERT INTO tblFoundation (MyStringA, MyStringB, MyStringC, MyStringD) VALUES (Design,"Height of Interior Drive-Thru to Adjacent Floor,"Z999,"Floor slab of Drive Aisle and Auto Loading Area to be set 4" below adjacent floor slabs. []")

It is like " marks are missing maybe?
Gustav BrockCIOCommented:
You can use the RecordsetClone of the target subform:

Dim rs As DAO.Recordset

Set rs = Me.Parent!NameOfTargetSubformControl.Form.RecordsetClone
    rs!SomeField.Value = Me!FirstSourceField.Value
    rs!AnotherField.Value = Me!SecondSourceField.Value
    rs!YetAField.Value = Me!ThirdSourceField.Value
    ' etc.

Open in new window

The target will update automatically.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>> It is like " marks are missing maybe?

Yup... you need to delimit all text data with quotes. Also, the double quotes in the memo field data are problematic with this method.

Use the recordset method that Gustav suggested instead.  If you are unclear about which delimiters go where, the recordset approach has the advantage that no delimiters are required.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.