Full Version: Automate Copy Paste From One Form To Another
UtterAccess Forums > Microsoft® Access > Access Forms
justinhampton81
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?
theDBguy
Hi,
Could you use a form/subform instead that are linked on the CityID?
Just curious...
justinhampton81
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.
theDBguy
I see... Are you trying to copy the ID to a new record?
justinhampton81
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.
theDBguy
Okay, maybe you could try something like this:
!--c1-->
CODE
Private Sub CityID_DblClick(Cancel As Integer)
   Parent.SubformControlName.SetFocus
   DoCmd.GoToRecord , , acNewRec
   Parent.SubformControName.Form!CityID = Me.CityID
End Sub

(untested)
Just my 2 cents... 2cents.gif
BruceM
Don't be so sure about that < -- http://allenbrowne.com/ser-32.html
zocker
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!
Best!
Zocker
B
justinhampton81
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?
Me.Parent.Parent!subFormControlName.SetFocus
thanks for the help guys.
theDBguy
Hi,
If both subforms are three levels deep, then you could try something like:
Parent.Parent.SubformControlName.SetFocus
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.