Duplicate Data Error While Saving An Edited Record

Jan 8, 2005

Having a problem when saving a record that has been edited and contains a duplicate field. Here is what I'm doing.

I have an existing record that is being viewed by the user. I have an edit button on the form that is displaying the record. When the user clicks the edit button I do the following

'User clicked on edit customer record

Private Sub CustEditRec_Click()

'Store current customer key in string so we can cross

'check if user has changed the key during edit

EditCustKey = Me.txtCustomerKey

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

'Set customer record test string so we can determine

'what the user is doing

CustomerRecStat = "edit"

' Go unlock the customer data fields for editing

UnlockCustomerFields

TxtCompanyName.SetFocus

'Go Unlock the customer editing buttons

UnLockCustomerAddButtons

'Lock the add, delete, edit buttons

CustAddRec.Enabled = False

CustEditRec.Enabled = False

CustDelRec.Enabled = False

'Go Disable the customer navagation buttons

DisableCustomerNavigation

txtCustomerKey.Visible = True

txtCustomerKey.Locked = False

txtCustomerKey.Enabled = True

'Set focus on the customer key

txtCustomerKey.SetFocus

'disable & hide the customer key combobox

cmboCustomerKey.Locked = True

cmboCustomerKey.Enabled = False

cmboCustomerKey.Visible = False

Exit_CustEditRec_Click:

Exit Sub

Err_CustEditRec_Click:

MsgBox Err.Description

Resume Exit_CustEditRec_Click

End Sub

The field which duplicate entries are not allowed in the table is txtCustomerKey. Now remember we are just editing a record NOT ADDING A NEW ONE.

When the user finished making the changes to the record we use the same procedure to save the changes as we when the user is adding a new record...here it is.

'User clicked save customer record

Private Sub CustSaveRec_Click()

On Error GoTo Err_CustSaveRec_Click

SaveCustomerRecord:

'Update the table data fields with the data contained on the form

CustomerKey = Me.txtCustomerKey

CustomerCompany = Me.TxtCompanyName

CustomerFirst = Me.txtCustomerFirst

CustomerLast = Me.txtCustomerLast

CustomerAddress = Me.txtCustomerAddress

CustomerCity = Me.txtCustomerCity

CustomerProvince = Me.txtCustomerProvince

CustomerPostal = Me.txtCustomerPostal

CustomerCountry = Me.txtCustomerCountry

CustomerPhone = Me.txtCustomerPhone

CustomerFax = Me.txtCustomerFax

CustomerEmail = Me.txtCustomerEmail

CustomerWeb = Me.txtCustomerWeb

CustomerNotes = Me.txtCustomerNotes

'Save the record

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

'*** IF WE GOT THIS FAR WITH OUT ERRORS WE SAVED THE RECORD

'*** GO AHEAD & DISABLE THE FORMS VARIOUS FIELDS

'*** & BUTTONS ONCE AGAIN AS WE ARE JUST BACK TO VIEWING

'*** THE CUSTOMERS DATABASE

'Enable and unlock the customer key field

txtCustomerKey.Visible = True

txtCustomerKey.Locked = False

txtCustomerKey.Enabled = True

'Hide & disable the customer keycombo box

cmboCustomerKey.Locked = True

cmboCustomerKey.Enabled = False

cmboCustomerKey.Visible = False

'Set focus on the customer key field

txtCustomerKey.SetFocus

'Lock the customer fields

LockCustomerFields

'Enable the navigation buttons

EnableCustomerNavigation

'Lock the customer adding buttons

LockCustomerAddButtons

'Clear the record testing status

CustomerRecStat = ""

txtCustomerKey_AfterUpdate

Exit_CustSaveRec_Click:

Exit Sub

Err_CustSaveRec_Click:

'If the error generated was by a duplicate value.

'This can only be caused by the customer key as this

'is the only field which does not allow duplicate values.

'so warn the user of this duplicate value error and set

'the focus on the customer key field

If Err.Number = 3022 Then

'if user is editing a record

If CustomerRecStat = "edit" Then

'And the entered customer key has not changed

If Me.txtCustomerKey = EditCustKey Then

'Return to saving the record as the key is

'not really a duplicate

GoTo SaveCustomerRecord

End If

End If



Select Case MsgBox("This Customer ID was already located in the database. Click OK to enter a new Customer ID or Cancel to stop adding this record?", vbExclamation + vbOKCancel + vbDefaultButton1, "Duplicate Customer ID")

Case vbOK

Me.txtCustomerKey.SetFocus

Resume Exit_CustSaveRec_Click

Case vbCancel

'Go simulate undo record click

CustUndoRec_Click

Resume Exit_CustSaveRec_Click

End Select

End If

MsgBox Err.Description

Resume Exit_CustSaveRec_Click

End Sub



The problem is when the user is editing a record. The database assumes the txtCustomerKey is a duplicate in the table. However we are not adding a new record so the duplicate error is false. Its just that the txtCustomerKey is the same as the record being edited. Its not DUPLICATED its the SAME.....



Any help anyone? Sorry for the long post but I'm a strong believer in the more information the better when trying to solve a problem....

Thx

Kao

View Replies


ADVERTISEMENT

Duplicate Record Error

Dec 21, 2006

I'm trying to make a simple DB that we can enter our time for working on projects.

So far I have a Form with the employees name and the date in it. Then below that is a subform with the project number, name, client name, and hours.

I want to use this whole "sheet" for one days worth of work for 1 employee. New sheets will be used for each day.

When I try to make a new sheet I get an error that it cant change the table because it would be creating a duplicate entry.

How do I solve this?

Also, should it be difficult to be doing what I'm trying to do?

View 2 Replies View Related

Duplicate Record Error

Aug 17, 2005

hi everyone,

i have a form that i'm trying to create a button to duplicate the record. i'm using the control wizard which produces the following code:

Private Sub DuplicateRecord_Click()
On Error GoTo Err_DuplicateRecord_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70

Exit_DuplicateRecord_Click:
Exit Sub

Err_DuplicateRecord_Click:
MsgBox Err.Description
Resume Exit_DuplicateRecord_Click

End Sub

When i try to execute the code via a comand button, i get an error and the duplicate record operation does not occur. one thing i noticed is that i have a lot of lookup fields (i.e. FK's to lookup tables one-to-many relationships) in underlying table being populated by the form. i've created combo boxes on the form to populate the FK's in the underlying table. the error that occurs when trying to use the above code produces a "paste errors" table and in that paste errors table instead of the bound column values from the combo boxes (i.e. PK values from the lookup tables) it shows the display values from the combo boxes. i'm not sure if this has do with anything, but i couldn't figure out why it was doing this.

does anyone have any ideas how i could get this duplicate record procedure to work?

many thanks for any help or suggestions.

View 1 Replies View Related

Error Making Duplicate Record

Apr 9, 2014

I am having an issue with one person having trouble getting an error when trying to duplicate a record.

The subform is set up with a button to duplicate a record. This allows most of the data that stays the same to be copied to a new records and then minor changes can be made to update the record for the new month. Since there are memo fields, in these records, this saves a lot of retyping. One person who is using the database gets the following error when clicking on the duplicate record button.

The command or action 'Copy' isn't available now.

It makes a new blank record but won't copy over the information. You can go to the record and copy each field individually and paste it into the new record, but this is not very practical.

I have not been able to duplicate the error and no one else using the database is having this happen.

View 5 Replies View Related

Modules & VBA :: Error Message On Creating Duplicate Record

Jul 25, 2013

I need to be able to produce an error on a form where the user attempts to create a new user that already exists. The error needs to be produced when the save button is clicked.

See below for the existing code on my save button which exists in form, 'frmAddEditUser':

Private Sub cmdSave_Click()
If IsNull(cboManagerID) = True Then
MsgBox "Please select a manager", vbExclamation, "Details Missing!"
Me.cboManagerID.Requery

[Code] ....

Currently, if I attempt to create a user with the same Payroll ID as an existing user, my 'User details saved' message box is displayed and to the user it looks like a new record has saved successfully which isn't the case.

I need a message box to appear displaying something like "Payroll ID n already exists" where n is the 'PayrollID' of the duplicate record. (Is it possible to combine a value from a certain control and ones own custom text?)

Note: PayrollID is a combination of letters and numbers, i.e. two letters, followed by 5 numbers, e.g. JD12345.

For reference, the table/field and and control are called, '[tblUser].[PayrollID]' and 'txtPayrollID' (on 'frmAddEditUser') respectively; it is from this field and control that I want the error to be produced if the user is entering the same values which are existing in 'tblUser'.

View 10 Replies View Related

Forms :: Error On 2nd Combo When Adding A Duplicate Record?

Jun 7, 2015

error message I am getting when I click on my Duplicate Record button (created through the wizard).

I have two combo boxes on the main form that populates data when the user makes a selection from the combo box. First combo box populates project data and the second combo box populates equipment data. The form is working well with the two combo boxes populating the data into the main table.

Now I would like to add a duplicate record button to copy a record and paste the data as a new record. So, I added a duplicate record button using the wizard and I am receiving the following AfterUpdate error.

Run-time error 3020: Update or CancelUpdate without AddNew or Edit.

This is the code I am using to copy and paste a duplicate record:

Private Sub InputForm_DupRec_Button_Click()
On Error GoTo Err_InputForm_DupRec_Click
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend
Exit_InputForm_DupRec_Click:
Exit Sub
Err_InputForm_DupRec_Click:
MsgBox Err.Description
Resume Exit_InputForm_DupRec_Click

It seems to be duplicating the data from the first combo box, but not the second one where it errors out.

View 1 Replies View Related

Custom Error Message For Duplicate Data?

Apr 26, 2013

How to create custom error message for duplicate data? I want this custom message at text box before_update event not at form_error .....

View 1 Replies View Related

Forms :: Continuous Form - Saving New Record When Data Passed To It

Dec 11, 2013

I have a continuous form it has a field (DateStart) and a field (DateStartCarryOver). There is an event on (DateStart) for the (DateStart.Value) to be passed to a new record in (DateStartCarryOver).

My probem is that the new record dosent get saved (i.e. it dosent get an ID so a record isnt created. How can I create that record once the data has bee pased to it?

View 3 Replies View Related

Q? Find Last Edited Record Using DMax And FindRecord

Oct 27, 2004

Hi,

I have a database / form with a hidden timestamp field [LastEdit]
that is filled automatically with the current time Now() when updated.
The purpose is that each time the form is opened I want it to "Goto" the last edited record.

I *think* I get around the find edit quotes because the smaller snippets below do work.

findit = DMax("[LastEdit]", "esn")
MsgBox DMax("[LastEdit]", "esn")

But the whole thing fails when I put it into one command as either one of these
DoCmd.FindRecord DMax("[LastEdit]", "esn"), , , acSearchAll
or DoCmd.FindRecord findit, , , acSearchAll
perhaps because of the quotes around the variable.

Any ideas?

Thank you,

View 4 Replies View Related

Adding A New Record, But Not Allowing Old Records To Be Edited

May 6, 2005

I have a problem that should have an easy solution. But I can't find it.

I need to have a user add a new record. (Created a form with the fields on it, No problem , so far.)

The problem is when the user is adding a new record if they hit the PAGE DOWN Key or the mouse scroll, they then go to a new NEW record. (And if they are not paying attention they now have two new records)

How do I prevent this.

Thanks

Mike Lester

View 2 Replies View Related

Update Separate Table When Record Is Edited

Aug 5, 2015

I have a form where a user can change the scheduled start date for a job. On a sub form on the same screen is a list of notes relating to that job.

Any notes added, automatically have todays date and are locked when the user clicks off.

When the scheduled start date is changed I need a note to be made. Either forced, then entered by the user or automatically.

I was thinking of making the scheduled start appear in a small form and the button to make it come up could add a new note on the click event (possibly in a message).

Or even better (probably harder) any time the value is changed in the form a new note is added.

Other options could be a pop up form to add one note on a change.

View 4 Replies View Related

Goto Previous EDITED Record On Continious Form

Sep 29, 2005

Hi All,

I have a continious form where each record can be edited. After editing a record the form does a me.save and a me.requery (is important). After this it jumps back to the first record (seems logical), but how can I write a code that he goes back to the 'previous edited record'.

Thanks.

View 4 Replies View Related

Creating New Record When Record Is Edited?

Feb 20, 2015

I'm working on a project that has project start / end dates which can change. A report is created based on this data. The customer wants me to save all changes as a new record and disregard the older record when the report is created. I was thinking that I would add a (yes/no) column that marks the new record as the most recent (yes) and marks older records as (no). Then I would modify the query for the report to only include records with 'yes' set to true. I was also thinking that I should create a second table that has a foreign key for the original record from the main table. The main table would have the most recently edited record while the second table would have the previous records. Which method should I use?

View 3 Replies View Related

Forms :: Saving New Record When Moving To Another Record In Same Subform

Jan 17, 2014

I have a subform with records of call details (date, time, subject) - the date and time are autogenerated and subject is a text field. After entering text in the subject field and then clicking on the close button in the main form, or clicking anywhere else in the main form, the record is saved to the table. However, if I enter text in the subject field and then move up to view previous records (within the subform) and then click the close button in the main form the record is not saved in the table. How can I either save the record before allowing the user to move to another record within the subform or before exiting the subform set the focus to the new record so that it will be saved on exit?

View 4 Replies View Related

Saving Access Reports Into Multiple PDF / Error 3014?

Oct 2, 2015

I'm running into a Run time error 3014 Cannot Open Any More Tables

I have a report in Access and I am using the below VBA to save the file by the content of the "File" column in the DOC_AP_MASTER table. It works wonderfully for about 60-120 (it ranges and I don't know why) but then I get the lovely error above.

My report closes after each save... what tables am I opening without knowing?

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim MyFileName As String
Dim mypath As String
Dim temp As String
mypath = "C:Testing"

[code]....

View 14 Replies View Related

Forms :: Saving Specific Data From Data Entry Form Depending On User Selection

Dec 18, 2014

I am trying to save specific data from a data entry form to a specific depending on what the user selects from a dropdown/combo box.

So if the user selects "test company from the combo box, that data (from that form) will save to the Test company data table.

View 5 Replies View Related

Refreshing A Data Entry Form After Saving Data

Jul 6, 2005

This has most definitely been asked before but I really cant find anything on the forum! Ive created a data entry form which has a save button which the user must click each time to save the record. However how do I refresh the form i.e. empty all data from the previous record without exiting the form. Ive tried to combine the undo macro but that simply deletes the previous record. Any help please!!!

View 3 Replies View Related

Duplicate Key Error !!!!!

Jun 14, 2005

Hi there

I have the following field in my access project.

Sno
Name
PortNo
Location
Speed
Package

In the above field i had set Sno is PRIMARY KEY. The problem is after entering all field, then only it will show the duplicate Sno error. What I want is, if Sno is duplicate, when i type SNo , successively i have to get the SNo is duplicate.

Help me to solve this issue

thanx in advance

by
yasi

View 2 Replies View Related

New Record On Saving

Apr 5, 2006

Hello guys

I have one small quick question. How can get blank or new record after saving

Cheers

View 3 Replies View Related

Saving A Record AS A NEW RECORD From A Form

Nov 23, 2006

Iam very new to ACCESS. So please do forgive me for
believing that the "SAVE AS" function in ACCESS is as easy as
something similar we do in Microsoft Word.

After searching this forum and others I realise that there is no easy way
and it is considered as some thing for serious users.
(with additional coding not available in ACCESS)
Perhaps there are easier ways that I am not aware of.

I would like to open a record in a FORM which has one Combo Box
for text data, several text and Numeric fields.
I then need to change a few items and save the record as a New
Record
Only a few (mostly numeric fields) and some date entries will be changed
as well as a couple of calculated fields in the NEW RECORD.

I shall appreciate any suggestion as to how to do this.

View 13 Replies View Related

Duplicate Error Message Help

Jul 6, 2005

hi,

the below scrip was taken from another forum member.

i have put this in the Forms / error VBA

but i still a little lost

i have set 3 fields to be indexed not to allow duplicate information (Forename, Surename, DOB)

i was then advised to error trap so it would highlight that i have enterd a duplicate record on typing in the DOB (As that as third feild to be entered)

so i then used the below script, however this doesnt highlight that it is a duplicate it just doesnt let me go on to the next record, the only time the error message is highlighted is when i go into design mode.

anyideas on where to go from here.


Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3022 Then
Response = acDataErrContinue
MsgBox "Tis MerID alredy exist!"
Exit Sub
End If
If DataErr = 2169 Then
Response = acDataErrContinue
MsgBox "Tis record will not be saved!"
Exit Sub
End If

End Sub

View 3 Replies View Related

Saving A Record On Lost_focus

Jun 26, 2006

I'm terribly sorry to bother on what seems like a very simple matter, but I've just given up on MicroSofts documentation.

I just want to execute the Shift+enter type of save-record command (also available from the "Records" menu at the top) when a field loses focus. This would need to be part of my VB code as I'm doing other things on this event as well.

Any help is greatly appreciated.

View 1 Replies View Related

Saving Record From Form

Feb 23, 2005

Hello,
I have a form and I have a button so people can open records to load into the form. The problem is that whenever they close the form it updates the information in the table. How do I stop that from happening?
I want the information in the table to update only when they hit the button I made (which works).

And how do I stop it from loading the record when I open the form, or maybe I can specify to load a blank record instead, how do I do that?

Thanks in advance!

View 1 Replies View Related

Vb Code For Saving A Record

Feb 22, 2006

Hi,

This should be an easy one...I would like to save a record part-way while filling out a form. I know this can be accomplished by pressing Shift+Enter, but does anyone know the vb code for saving a record while working on a form?

Thanks.

View 1 Replies View Related

Record Saving Woes

Mar 16, 2006

Ok, here is my scenario.

I have several FE's each saving in their own BE. They are all the same but for different areas of our business. Each has around 20-30 users. I recently introduced another form into the FE that has linked tables to another different BE in another folder. Each FE out there with its own BE now has this form and all of the new forms save to the same (one) BE. Ok, got it?

Now, sure its possible to have them all together and I would anticipate someone suggesting this. Its split up to keep sizes down and performance up among other reasons.

In any event, here I am. All of the new form introductions went smoothly without a hitch. The last one however is causing trouble. On submit an e-mail is sent, the user is asked if they want to submit another form, and if yes a new record is created. If no the form is closed.

E-mails are always sent, no problem. The trouble is saving the record. All except one of the different FE's I have out there in different folders save the record into the table just fine. There is one though that does not do this. The mail is sent and the program behaves normally with no errors but the record is not saved. This does not happen to all users of this FE either. There are some users that work fine and the record is saved in the BE yet other users do not save the record. You can see the .ldb appear and disappear. Our IT dept has been through the permissions time and time again and tell me they are ok. The FE and main BE are in one folder while the BE that the new form talks to is in its own folder. Remember, this works fine for several other instances, its just the one that doesn’t save the record.

I did have a chance to see the permissions the other day and it seems a mess to me. They have users in individually, as they were set up initially and the same users are also in there in a group and maybe 2 groups. The permissions look a mess to me… they really do…. but that doesn’t necessarily mean they would not work and can be blamed. I have no control over this part and it drives me nuts!

What I have done...... copied a working FE from another area into the troubled folder. No good. I have removed the new form along with its linked tables and the record is saved. Put the form and linked tables back in and it stops saving again. The code compiles just fine. I have done compact and repairs.

Any thoughts or ideas out there??? If you need more info ask. I understand what I wrote but you might not LOL

View 8 Replies View Related

Vba Code For Saving A Record

Apr 13, 2006

hola,

does anyone know the code to save a report with a changing file name?

here are the details.
i have a reoprt that changes weekly. i want to save a weekly file with the end result to be called "Downtime Cost Report #/##/##", where the date is pulled in from a qry called "qry_Actual_Costs_Thru" and field name [Fiscal Week].

i know it is something like:

DoCmd.Save acReport, "Downtime Cost Report"

Thanks
T

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved