PC Review


Reply
Thread Tools Rate Thread

create new row/record using existing row as source

 
 
=?Utf-8?B?ZGZlaWdlbjExNQ==?=
Guest
Posts: n/a
 
      14th Sep 2006
Occasionally, my users need to create a new record in the database using the
values of an existing record (in the same databvaase) as the source. The
primary key to the table is an "autonumber" field. Ultimately, I'd like to
be able to have the user specif y the source record, have the system create a
new record using some (not all) field values of the source record; open the
"edit" form with the new record as the source.

Thanks in advance for any suggestions.....
 
Reply With Quote
 
 
 
 
Marshall Barton
Guest
Posts: n/a
 
      15th Sep 2006
dfeigen115 wrote:

>Occasionally, my users need to create a new record in the database using the
>values of an existing record (in the same databvaase) as the source. The
>primary key to the table is an "autonumber" field. Ultimately, I'd like to
>be able to have the user specif y the source record, have the system create a
>new record using some (not all) field values of the source record; open the
>"edit" form with the new record as the source.



Here's one way to copy (some of) the current record's values
to a new record and then navigate to the new record:

Sub CopyButton_Click()
With Me.RecordsetClone
.AddNew
!flda = Me.flda
!fldc = Me.fldc
. . .
.Update
Me.Bookmark = .LastModified
End With

Note that this saves the copy back to the source table, so
if the user decides they didn't want to do that, you'll have
to provide a delete button (i.e Esc or Undo will not cacel
the new record).

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
 
 
 
=?Utf-8?B?ZGZlaWdlbjExNQ==?=
Guest
Posts: n/a
 
      15th Sep 2006
Thanks Marshall, I'll give it a shot.

"Marshall Barton" wrote:

> dfeigen115 wrote:
>
> >Occasionally, my users need to create a new record in the database using the
> >values of an existing record (in the same databvaase) as the source. The
> >primary key to the table is an "autonumber" field. Ultimately, I'd like to
> >be able to have the user specif y the source record, have the system create a
> >new record using some (not all) field values of the source record; open the
> >"edit" form with the new record as the source.

>
>
> Here's one way to copy (some of) the current record's values
> to a new record and then navigate to the new record:
>
> Sub CopyButton_Click()
> With Me.RecordsetClone
> .AddNew
> !flda = Me.flda
> !fldc = Me.fldc
> . . .
> .Update
> Me.Bookmark = .LastModified
> End With
>
> Note that this saves the copy back to the source table, so
> if the user decides they didn't want to do that, you'll have
> to provide a delete button (i.e Esc or Undo will not cacel
> the new record).
>
> --
> Marsh
> MVP [MS Access]
>

 
Reply With Quote
 
=?Utf-8?B?ZGZlaWdlbjExNQ==?=
Guest
Posts: n/a
 
      15th Sep 2006
Marshall,

The "copy" is working fine, thank you.

I do have a followup question... How can I access/capture the value of the
primary key (autonumber) that was created when the clone was saved? The idea
being once the new record is saved, open an edit form populated with data
from the new record so that the users can tweak anything as needed.

Dan

"dfeigen115" wrote:

> Thanks Marshall, I'll give it a shot.
>
> "Marshall Barton" wrote:
>
> > dfeigen115 wrote:
> >
> > >Occasionally, my users need to create a new record in the database using the
> > >values of an existing record (in the same databvaase) as the source. The
> > >primary key to the table is an "autonumber" field. Ultimately, I'd like to
> > >be able to have the user specif y the source record, have the system create a
> > >new record using some (not all) field values of the source record; open the
> > >"edit" form with the new record as the source.

> >
> >
> > Here's one way to copy (some of) the current record's values
> > to a new record and then navigate to the new record:
> >
> > Sub CopyButton_Click()
> > With Me.RecordsetClone
> > .AddNew
> > !flda = Me.flda
> > !fldc = Me.fldc
> > . . .
> > .Update
> > Me.Bookmark = .LastModified
> > End With
> >
> > Note that this saves the copy back to the source table, so
> > if the user decides they didn't want to do that, you'll have
> > to provide a delete button (i.e Esc or Undo will not cacel
> > the new record).
> >
> > --
> > Marsh
> > MVP [MS Access]
> >

 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      15th Sep 2006
Add a line before the .Update
lngPK = !pkfieldname

Can't users edit the new record in the same form where we
copied the record?
--
Marsh
MVP [MS Access]


dfeigen115 wrote:
>The "copy" is working fine, thank you.
>
>I do have a followup question... How can I access/capture the value of the
>primary key (autonumber) that was created when the clone was saved? The idea
>being once the new record is saved, open an edit form populated with data
>from the new record so that the users can tweak anything as needed.
>
>>
>> "Marshall Barton" wrote:
>>
>> > dfeigen115 wrote:
>> >
>> > >Occasionally, my users need to create a new record in the database using the
>> > >values of an existing record (in the same databvaase) as the source. The
>> > >primary key to the table is an "autonumber" field. Ultimately, I'd like to
>> > >be able to have the user specif y the source record, have the system create a
>> > >new record using some (not all) field values of the source record; open the
>> > >"edit" form with the new record as the source.
>> >
>> >
>> > Here's one way to copy (some of) the current record's values
>> > to a new record and then navigate to the new record:
>> >
>> > Sub CopyButton_Click()
>> > With Me.RecordsetClone
>> > .AddNew
>> > !flda = Me.flda
>> > !fldc = Me.fldc
>> > . . .
>> > .Update
>> > Me.Bookmark = .LastModified
>> > End With
>> >
>> > Note that this saves the copy back to the source table, so
>> > if the user decides they didn't want to do that, you'll have
>> > to provide a delete button (i.e Esc or Undo will not cacel
>> > the new record).

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What are: "Control Source" , "Row Source" and "Row Source Type" ? ali Microsoft Access Forms 1 14th Jan 2008 03:12 AM
Can't Insert New Row Between Row and Row While Existing DataTable Looping Kelvin Microsoft C# .NET 0 13th Dec 2004 03:01 AM
Can't Insert New Row Between Row and Row While Existing DataTable Looping Kelvin Microsoft C# .NET 0 12th Dec 2004 01:22 PM
Can't Insert New Row Between Row and Row While Existing DataTable Looping Kelvin Microsoft C# .NET 1 11th Dec 2004 01:43 PM
Using pre-existing source - in a pre-existing location! Phill. W Microsoft VB .NET 1 23rd Aug 2004 02:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:12 AM.