Do not want form to auto save and create duplicate record (1 Viewer)

rlreynolds217

Registered User.
Local time
Today, 14:05
Joined
Oct 4, 2012
Messages
11
Hello,

I have a form that opens an existing record. I want to be able to save the record as a new record only if the last two digits of the ID (which is called Task Code) are changed. Right now, when I change the ID, it auto saves it in the form, then says I cannot create a duplicate ID because it would not have a unique ID. I believe i have the correct code for saving the duplicate record, however how do I get the form to NOT auto save? I am using Access 2010.
 

pr2-eugin

Super Moderator
Local time
Today, 19:05
Joined
Nov 30, 2011
Messages
8,494
The code that you currently have would go inside the Form's BeforUpdate event.. Where you can cancel the Update..
Code:
Private Sub From_BeforeUpdate(Cancel As Integer)
    'your code to evaluate if the record is Duplicate
    ' If that is a duplicate:
    Cancel = True
End Sub
 

rlreynolds217

Registered User.
Local time
Today, 14:05
Joined
Oct 4, 2012
Messages
11
Thanks, pr2-eugin,
It is still giving me the error "TPS Database may have encountered an error while trying to save a record. If you close this object now, the databahnges you made will be lost.", and that is even after I changed the last two digist of the Task Code. I also have a linked table (Details is primary, Financial is secondary), and it is saying that there won't be financial data on the "one side". Can you explain that?
 

pr2-eugin

Super Moderator
Local time
Today, 19:05
Joined
Nov 30, 2011
Messages
8,494
With the limited information, I am not sure how to deal with this.. Is it possible to show the code you have there.. Or better if you could upload a stripped down version of your DB?
 

rlreynolds217

Registered User.
Local time
Today, 14:05
Joined
Oct 4, 2012
Messages
11
Task Code is a 13 character string, with the first ten characters being the task code, the 11th being a hyphen, and the last two being the Fiscal Year digits. What I want the user to be able to do is go into an existing task code, pull up the detailed task code form, and be able to change the Fiscal Year digits and save the record as a new record. I also want it to update the Task Code in the Financial Table (secondary table) so that it inserts a new record linking the TPS Details (primary table).

I have attached the code in a pdf file.
 

Attachments

  • Detailed_Save_as_new code.pdf
    56.4 KB · Views: 101

pr2-eugin

Super Moderator
Local time
Today, 19:05
Joined
Nov 30, 2011
Messages
8,494
Okay you have implemented Macros.. Where I have described the use of VBA..

Sorry ! I am not that competent enough with Macros.. :( but I hope someone will be here along the way to help you out with Macros..
 

Users who are viewing this thread

Top Bottom