473,416 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Copy selected records and save as new rec with user input

Hello Group:

My first post on the group.Hope I get a response.
I have a modest Fire Insurance ACCES Db.Thanks to this group - for the
code. A "wanna be programmer"... "LEARNS"

The code here-under (from the Archive) duplicates the EXPIRING records
but affords the USER to give ONLY A NEW POLICY NO (NewKey),should a
client opt to renew upon expiry of the YEARLY POLICY.The NEW POLICY NO
is save as a NEW record along with the "old"static rec.

MY Need:
Could somebody help me "re-syntax"the code to accept the ff: flds via
"User Input" [NEWDATE_ISSUED], [NEWFROM_DATE],[NEWTO
_DATE],[NEW_flds],etc.
The system MUST RETAIN THE OLD RECORD.

I know DUPLICATION is a "boo-boo" in DB.
I'm working on it and I'll get there somehow.
Been working on this for days, smoke too many cig.!!

I need the code that works NOT "I'm stupid", I know that already"

ALL THE BEST!
josephm

'***************** Code Start *******************
'//This code from Jim Davis,University of Washington

NewKey = InputBox("Enter the new Policy No")
Dim DB as Database
Dim NewRS as Recordset, OldRS as Recordset
Dim SQL as String

'** Open recordsets.
SQL = "SELECT * FROM tablename WHERE (tablename.keyname ='"
SQL = SQL & txtKeyFieldOnForm & "');"
Set DB = DBEngine(0)(0)
Set OldRS = DB.OpenRecordset(SQL, DB_OPEN_DYNASET)
Set NewRS = DB.OpenRecordset("tablename", DB_OPEN_DYNASET)

'** Copy record
NewRS. AddNew
NewRS! KeyFieldName = NewKey

'** Copy remaining fields
For i = 1 to NewRS.Fields.Count - 1
NewRS(i) = OldRS(i)
Next i
NewRS.Update
NewRS.Close
OldRS.Close

'** Move form to new record
DoCmd ApplyFilter , "keyfieldnameintable ='" & NewKey & "'"

'***************** Code End **********************

Dec 10 '05 #1
2 2848
It is possible to create a clone of the recordset, so you have 2 sets of
pointers to the same records. You can then Addnew to the clone set, while
reading each field from the original record.

A really simple way to do this is to add a command button to the form where
the records are. The user finds the record to be renewed, and clicks the
Duplicate button. Its code adds the new record to the RecordsetClone of the
form, and then shows it to the user.

This kind of thing:

Private Sub cmdDupe_Click()
'On Error GoTo Err_Handler
'Purpose: Duplicate the record in the form.
Dim NewKey As String

'Save and edits first
If Me.Dirty Then
Me.Dirty = False
End If

'Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Select the record to duplicate."
Else
'Get the new key
NewKey = InputBox("Enter the new Policy No")
'You need to test there was an entry, and of a suitable type.

With Me.RecordsetClone
.AddNew
! KeyFieldName = NewKey
!OrderDate = Date
'etc for other fields.
.Update

'Show the new record
Me.Bookmark = .LastModified
End With
End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdDupe_Click"
Resume Exit_Handler
End Sub
BTW, you don't need to apologise for doing this. You are not duplicating the
same data, but quite correctly creating a new record for the new period. No
rules broken. Good strategy.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"josephm" <jo********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hello Group:

My first post on the group.Hope I get a response.
I have a modest Fire Insurance ACCES Db.Thanks to this group - for the
code. A "wanna be programmer"... "LEARNS"

The code here-under (from the Archive) duplicates the EXPIRING records
but affords the USER to give ONLY A NEW POLICY NO (NewKey),should a
client opt to renew upon expiry of the YEARLY POLICY.The NEW POLICY NO
is save as a NEW record along with the "old"static rec.

MY Need:
Could somebody help me "re-syntax"the code to accept the ff: flds via
"User Input" [NEWDATE_ISSUED], [NEWFROM_DATE],[NEWTO
_DATE],[NEW_flds],etc.
The system MUST RETAIN THE OLD RECORD.

I know DUPLICATION is a "boo-boo" in DB.
I'm working on it and I'll get there somehow.
Been working on this for days, smoke too many cig.!!

I need the code that works NOT "I'm stupid", I know that already"

ALL THE BEST!
josephm

'***************** Code Start *******************
'//This code from Jim Davis,University of Washington

Dim DB as Database
Dim NewRS as Recordset, OldRS as Recordset
Dim SQL as String

'** Open recordsets.
SQL = "SELECT * FROM tablename WHERE (tablename.keyname ='"
SQL = SQL & txtKeyFieldOnForm & "');"
Set DB = DBEngine(0)(0)
Set OldRS = DB.OpenRecordset(SQL, DB_OPEN_DYNASET)
Set NewRS = DB.OpenRecordset("tablename", DB_OPEN_DYNASET)

'** Copy record
NewRS. AddNew
NewRS! KeyFieldName = NewKey

'** Copy remaining fields
For i = 1 to NewRS.Fields.Count - 1
NewRS(i) = OldRS(i)
Next i
NewRS.Update
NewRS.Close
OldRS.Close

'** Move form to new record
DoCmd ApplyFilter , "keyfieldnameintable ='" & NewKey & "'"

'***************** Code End **********************

Dec 10 '05 #2

Dear Dr.Allan:

Thank you so much for the reply.
The procedure will take a while of "typing",but
the code works,my job gets easier and I get the "professional touch" on
my little DB.
Just what I need.
Till next time Dr.Allan

Happy New Year,EVERYONE !!
-josephm

*** Sent via Developersdex http://www.developersdex.com ***
Jan 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tlm | last post by:
Hello All, I have a form (FrmA) with a subform (SubFrmB) embedded in it. SubFrmB also has a subform embedded in it (SubFrmC) The form's recordsource is based on a table (TblA). SubFrmB's...
5
by: Daniel Tan | last post by:
Are there anyway to copy rows of records from one query to another query and then hide the records in source query ? Pls advise. Thanks. Regards, Daniel
1
by: Sean Howard | last post by:
Dear All, As is my want I need to do something in Access that seems simple but cannot fathom out. I have main form with two subforms, both datasheets with an almost identical table structure....
19
by: davidgordon | last post by:
Hi, I need some pointers/help on how to do the following if it possible: In my access db, I have the following: Tables: Products, Sub-Assembly, Product-Pack Table, Products
0
by: igendreau | last post by:
I have a database with a Header table. Each record in tblHeader has two One-to-Many Relationships: with tblLines and tblKeys. The HeaderID field ties tblHeader to the other two tables. The data...
5
by: Kaur | last post by:
Hi, I have been successful copying a vba code from one of your posts on how to copy and paste a record by declaring the desired fields that needs to be copied in form's declaration and creating two...
1
by: anniefs | last post by:
hi help me i m so much stuck int he code and i have no time .... i used ASP VBscipt and javascript functions with MS database javascript function add records in MS DB by using ASP vbscript...
3
by: royd16 | last post by:
Hi!, can some help me with a problem? Here are my tables: User, Profiles, and one for "Profiles per user" In the last one, I save the ID of the user and the ID of the profiles for that user....
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.