copy data from a record to a new record

  • Thread starter Thread starter Karen
  • Start date Start date
K

Karen

I want to be able to have the users of my program open a form and enter a
product code, view the data for that product and then click a button to copy
the data to a new record in the tables. I have the search working. When I
do the copy (I have dim'd variables and done vardesc = me![flddesc]) and
open the form to add a new record the data doesn't 'paste' in with the
me!flddesc = vardesc. The frmnew reagent opens. I am pasting the code in
below. Please reply with any assistance. Thank you.

Karen

-----------------------------------

'save all flds from form to variables
Dim vardesc As Variant, vardesc2 As Variant, varcrdate As Variant
Dim varinit As Variant, varoffshore As Variant, varbatchmin As Variant,
varbatchmax As Variant
Dim varshelflife As Variant, varexpires As Variant, varprep As Variant
Dim varspecreq As Variant, varqcsafe As Variant, varqccheck As Variant

vardesc = Me![flddesc]
vardesc2 = Me![flddesc2]
varbatchmin = Me![fldbatchmin]
varprep = Me![fldprepproc]

' open frm new reagent
DoCmd.OpenForm "frmnew reagent", acNormal, , , acFormPropertySettings,
acWindowNormal


'fill in flds w/ variables
Me![flddesc] = vardesc
Me![fldprepproc] = varprep
 
Karen,

It's a reference issue:
'fill in flds w/ variables
Me![flddesc] = vardesc
Me![fldprepproc] = varprep

The Me. keyword references the object the module belongs to (form,
report), in this case the search form. So, it works well for reading the
values in the controls, but when you try to set the values in the
controls on the other form, you are actually setting the values of the
controls on the original form instead; of course, the values being the
same, you don't see that. Also, you don't get an error because controls
with the same names exist on both forms; if the "target" controls had
different names then you would get an error, as VBA wouldn't be able to
find them. You need to reference the target controls explicitly, like:

Forms![frmnew reagent]![flddesc] = vardesc
Forms![frmnew reagent]![fldprepproc] = varprep

HTH,
Nikos
 
That's it!!!
Thank you Nikos.



Nikos Yannacopoulos said:
Karen,

It's a reference issue:
'fill in flds w/ variables
Me![flddesc] = vardesc
Me![fldprepproc] = varprep

The Me. keyword references the object the module belongs to (form,
report), in this case the search form. So, it works well for reading the
values in the controls, but when you try to set the values in the
controls on the other form, you are actually setting the values of the
controls on the original form instead; of course, the values being the
same, you don't see that. Also, you don't get an error because controls
with the same names exist on both forms; if the "target" controls had
different names then you would get an error, as VBA wouldn't be able to
find them. You need to reference the target controls explicitly, like:

Forms![frmnew reagent]![flddesc] = vardesc
Forms![frmnew reagent]![fldprepproc] = varprep

HTH,
Nikos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top