Copying a field from one form to another.

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,

DHP, Inc.
Who is Participating?
walterecookConnect With a Mentor Commented:
Several ways to get there.
One is this for your open button

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

I take it that you are using Access?
haszanAuthor Commented:
Yes,i'm using access.
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

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.

That's a good way too.
Well done AW.
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.

haszanAuthor Commented:
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,

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.


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.