Create "Copy previous record" on a continous form

G

Guest

I am trying to create some kind of command button where if a user needs to
add a new record, he/she can use info from another record displayed on the
current continous form to populate their new record. I am stuck on how to
proceed to grab some of the fields from a record that they want to re-use a
good bit of info in a new record except for 1 or 2 fields possibly. How do I
go about doing that?
 
M

Marshall Barton

worksfire1 said:
I am trying to create some kind of command button where if a user needs to
add a new record, he/she can use info from another record displayed on the
current continous form to populate their new record. I am stuck on how to
proceed to grab some of the fields from a record that they want to re-use a
good bit of info in a new record except for 1 or 2 fields possibly. How do I
go about doing that?


The code behind your Dup command button could be along these
lines:

With Me.RecordsetClone
.AddNew
!thisfield = Me.thisfield
. . .
!thatfield = Me.thatfield
.Update
Me.Bookmark = .LastModified
End With
 
G

Guest

Hey Marshall,
Thanks for the info about RecordSetClone. Hadn't heard of it before. I am
having a little problem getting the code to work. For simlicity, I only put
one of the fields to copy for now.

Private Sub txtCopy_Click()
With Me.RecordsetClone
.AddNew
![txtAcct#] = Me.[txtAcct#]
.Update
Me.Bookmark = .LastModified
End With
End Sub

I get an error on the line ![txtAccount#] = Me.[txtAcct#] saying "Item not
in collection." It is referring to the ![txtAcct#] part of that line because
the stuff on the right of the equal sign finds the correct account # as
'144602' for the record I am copying.

What is wrong with my code right there?
 
M

Marshall Barton

It appears that you are confused about the difference
between the words "Field" and "Control". A Field is a
coulmn in a table or query, Controls are the thingies you
use on a form or report to display values (a bound control
displays the value of a field).

In your code, you must use ![some field] to the left of the
= sign. (The value on the right of the = sign can be any
expression, but for your record copy question is usually the
same field name.)

I don't know the names you are using, but I will guess that
you can use either:

![Acct#] = Me.[Acct#]
or
![Acct#] = Me.[txtAcct#]
--
Marsh
MVP [MS Access]

Thanks for the info about RecordSetClone. Hadn't heard of it before. I am
having a little problem getting the code to work. For simlicity, I only put
one of the fields to copy for now.

Private Sub txtCopy_Click()
With Me.RecordsetClone
.AddNew
![txtAcct#] = Me.[txtAcct#]
.Update
Me.Bookmark = .LastModified
End With
End Sub

I get an error on the line ![txtAccount#] = Me.[txtAcct#] saying "Item not
in collection." It is referring to the ![txtAcct#] part of that line because
the stuff on the right of the equal sign finds the correct account # as
'144602' for the record I am copying.

What is wrong with my code right there?

Marshall Barton said:
The code behind your Dup command button could be along these
lines:

With Me.RecordsetClone
.AddNew
!thisfield = Me.thisfield
. . .
!thatfield = Me.thatfield
.Update
Me.Bookmark = .LastModified
End With
 
G

Guest

Naw, I know the difference between a field and control. I call the controls
"thingies" myself in my mind :) Actually I just wasn't thinking when I
referenced my controls in my code after looking at your sample. I have been
in such form development mode lately that the controls are predominant in my
mind using Me.controlname all over the place. You can use Me.fieldname too
apparently :0) Thanks for your help. Works fine now that I followed your
sample.

How come you and so many others take the time to answer our questions which
must seem so rudimentary to you expert developers? I dabble here and there
to meet my needs and hope when I learn something it sticks permanently so I
can use that new tool later!

Marshall Barton said:
It appears that you are confused about the difference
between the words "Field" and "Control". A Field is a
coulmn in a table or query, Controls are the thingies you
use on a form or report to display values (a bound control
displays the value of a field).

In your code, you must use ![some field] to the left of the
= sign. (The value on the right of the = sign can be any
expression, but for your record copy question is usually the
same field name.)

I don't know the names you are using, but I will guess that
you can use either:

![Acct#] = Me.[Acct#]
or
![Acct#] = Me.[txtAcct#]
--
Marsh
MVP [MS Access]

Thanks for the info about RecordSetClone. Hadn't heard of it before. I am
having a little problem getting the code to work. For simlicity, I only put
one of the fields to copy for now.

Private Sub txtCopy_Click()
With Me.RecordsetClone
.AddNew
![txtAcct#] = Me.[txtAcct#]
.Update
Me.Bookmark = .LastModified
End With
End Sub

I get an error on the line ![txtAccount#] = Me.[txtAcct#] saying "Item not
in collection." It is referring to the ![txtAcct#] part of that line because
the stuff on the right of the equal sign finds the correct account # as
'144602' for the record I am copying.

What is wrong with my code right there?

Marshall Barton said:
worksfire1 wrote:

I am trying to create some kind of command button where if a user needs to
add a new record, he/she can use info from another record displayed on the
current continous form to populate their new record. I am stuck on how to
proceed to grab some of the fields from a record that they want to re-use a
good bit of info in a new record except for 1 or 2 fields possibly. How do I
go about doing that?


The code behind your Dup command button could be along these
lines:

With Me.RecordsetClone
.AddNew
!thisfield = Me.thisfield
. . .
!thatfield = Me.thatfield
.Update
Me.Bookmark = .LastModified
End With
 
M

Marshall Barton

worksfire1 wrote:
[snip]
Works fine now that I followed your sample.

How come you and so many others take the time to answer our questions which
must seem so rudimentary to you expert developers?


It's nice to hear that you have it working.

I guess the most important reason I (we?) answer questions
is because I get some kind of satisfaction from helping
others. There's also a vague sense of obligation to pay
forward for all the help I have received in the past. Then
there's the fact that I really like hanging out with very
smart people, especially the other MVPs.
 

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

Top