Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save current record only ?

Status
Not open for further replies.

stonehead

Technical User
May 2, 2007
58
US
Hi all,
This is what I'm trying to do.
A form with multiple controls. Users enter data, save it/ or open the form with saved data. Because a lot of cases, the data is pretty much the same, users just changes a couple things on the current record then hit button "Save as New Record" My problem is, access does not only save new data as new record but also save change to the previous record too. Can you help. Thanks a lot.
My sample codes:


Private Sub cmdSaveAsNew_Click()

'get current data
strJur = [Forms]![frmDataEntry]![txtJurCode]
strYear = [Forms]![frmDataEntry]![txtYear]
strSignedDate = [Forms]![frmDataEntry]![txtSignedDate]


'go open new record
DoCmd.GoToRecord acDataForm, "frmDataEntry", acNewRec

'copy data to form's controls of new record
[Forms]![frmDataEntry]![txtJurCode] = strJur
[Forms]![frmDataEntry]![txtYear] = strYear
[Forms]![frmDataEntry]![txtSignedDate] = strSignedDate

'save to table
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, acMenuVer70
 
Its not a good practice to change the existing current record, then create the new record...

The users should <Save as New Record> first, and edit this new record instead.

Max Hugen
Australia
 
You may try this:
...
'go open new record
Me.Undo
DoCmd.GoToRecord acDataForm, "frmDataEntry", acNewRec
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
In point of fact, in Access you cannot change an existing record and then instruct Access to "save it as a new record!"

You have to copy the desired controls to variables, move to a New Record, plug the variables back in to the controls on the New Record and then change anything you want changed.

The code you already have does just this! You simply need to click on cmdSaveAsNew, which takes you to a New Record, and then change anything you want changed!

And drop the line

Code:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, acMenuVer70

After entering the changed data in your New Record, simply save this New Record by moving to another record or closing your form.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top