Solved

Copying a field from one form to another.

Posted on 2004-04-02
8
1,011 Views
Last Modified: 2008-02-01
Hi everyone,

I would like to know if it possible to copy field from one form to another in the same database. I have form, that has "next" button on it, when clicked on it, a macro opens another form, and have it ready for me to add an entry, and closes the one it was on. I want to copy the customerID form A, to customerID in form b. The customerID in form A is auto number.

Kind regards,

Hassan
DHP, Inc.
http://www.dhp-inc.net
hassan@dhp-inc.net
0
Comment
Question by:haszan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10742195
I take it that you are using Access?
0
 
LVL 1

Author Comment

by:haszan
ID: 10742217
Yes,i'm using access.
0
 
LVL 17

Accepted Solution

by:
walterecook earned 125 total points
ID: 10742521
Several ways to get there.
One is this for your open button

docmd.openform "yournewForm"
forms!yourNewForm!CustomerID = me.customerID
DoCmd.Close acForm, "OldForm"

Walt
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10742725
or you can pass the CustomerID to the second form using the OpenArgs parameter on the DoCmd.OPenForm:

DoCmd.OpenForm "yournewform",OpenArgs:=CustomerID

then in the Form_Open procedure of the New form:

Private Sub Form_Open(Cancel as Integer)

   CustomerID.Text = OpenArgs

End Sub

here I am assuming that you have a TestBox on the NEW form, named CustomerID.

AW
0
 
LVL 17

Expert Comment

by:walterecook
ID: 10742854
Yup.
That's a good way too.
Well done AW.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10743094
using OPenArgs assures that the form will open with the correct data.  Trying to pass the value AFTER the form is already open, may or may not result in the proper data being displayed.

AW
0
 
LVL 1

Author Comment

by:haszan
ID: 10750193
Hi again,

the way Walt suggested seem to work for me, but out of curiousity why wouldn't the way Arthur suggested work for me? the following is the error message i get.

"Run-time error '2185':

you can't reference a property or method for a control unless the control has the focus"

thanks and kind regards,

Haszan
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10790287
becuase Access is rather retarded in that, in orrder to assign a value to a Property of a Control, THAT control MUST have 'focus'.  In full VB, that is NOT the case, and this line:

CustomerID.Text = OpenArgs


will work without problem in Full VB.  It was my mistake, as I normally code in VB 6 and VB.Net and not quite as much in VBA (in Access).  In Access, the line should have been:

CustomerID = OpenArgs

which makes use of the fact that, for a TextBox control. the TEXT property is the defualt, and thus it is NOT necessary to explicitly assign the value to the DEAFULT property, and this avoids the error message that you got, but accomplished precisely the same result.

Sorry about that.

AW

0

Featured Post

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question