Solved

Copying a field from one form to another.

Posted on 2004-04-02
8
969 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
Comment Utility
I take it that you are using Access?
0
 
LVL 1

Author Comment

by:haszan
Comment Utility
Yes,i'm using access.
0
 
LVL 17

Accepted Solution

by:
walterecook earned 125 total points
Comment Utility
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
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 17

Expert Comment

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

Expert Comment

by:Arthur_Wood
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now