Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Copying a field from one form to another.

Posted on 2004-04-02
8
Medium Priority
?
1,026 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
  • 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 500 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

580 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