Full Version: Automate Copy Paste From One Form To Another
UtterAccess Forums > Microsoft® Access > Access Forms
Here's a tricky one I can't quite figure out.
Let's say that I have a table that is a list of Cities in the US, and the other is a table of orders. Both are represented in subforms within a master form.
Right now, I'm just manually copying and pasting the City ID into the City ID field in my order table. I would like to be able to be able to go into the City table and double click the (or press a button, whatever, really...) and have that record's ID copied and pasted into the orders table.
Is there a way to automate that?
Could you use a form/subform instead that are linked on the CityID?
Just curious...
No, unfortunately the form UI isn't set up in a way where I could do that (they are already both subforms) and there are about 70,000 cities, so a drop down wouldn't work either.
I see... Are you trying to copy the ID to a new record?
yah, exactly. Right now, i'm just literally copying and pasting, but really wanted to automate pasting the ID from the City table into a new record (in a different table) with a double click or a button.
Okay, maybe you could try something like this:
Private Sub CityID_DblClick(Cancel As Integer)
   DoCmd.GoToRecord , , acNewRec
   Parent.SubformControName.Form!CityID = Me.CityID
End Sub

Just my 2 cents... 2cents.gif
Don't be so sure about that < -- http://allenbrowne.com/ser-32.html
For every textbox there is a Control source which is where its info is stored. It also has a Default Value which is a value entered 'automatically' this could be something like 234.99 or "Jim" or in your case, the value from another control on another Form..or subform. so if you set this Default to the textbox or other control on your 'outside' subfom you won't have to write any code or think about events. Now the most useful part of this is that the value from the 'other' subform is provided by the record you are working on..that is the Current Record... so you dont have to do any work there either.
o get the value of a control from another subform, use the expression builder which will do all the referencing for you. Click at the RHS of the Default Value property and the Expression builder appears!
Please post again for further help!
Zocker, thanks for this advice. I'm familiar with setting the default values and referencing other forms/subforms to pull the data. My question, though, is: how you have described, is it possible that the value is not set until a certain action (double click) within a record?
DBGuy - if the control source is nested 3 subforms deep, do I need to change the syntax so it is referencing the proper control source?
something like this?
thanks for the help guys.
If both subforms are three levels deep, then you could try something like:
DoCmd.GoToRecord , , acNewRec
Parent.Parent.SubformControlName.Form!CityID= Me.CityID
(still untested)
Just my 2 cents... 2cents.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.