Results 1 to 2 of 2
  1. #1
    dmilem is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    1

    .AddNew worked in Access 2003 but doesn't work in 2010

    I'm hoping someone can provide some insight on this one. The following code worked using Access 2003, but no longer works with Access 2010. It fails on the Recordset.Addnew statement. The error message says: The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship.



    Any suggestions would be greatly appreciated.

    Private Sub cmdAddNew_Click()
    On Error GoTo Err_cmdAddNew_Click
    Me.AllowAdditions = True
    Me.Filter = ""
    Me.FilterOn = False
    Me.OrderBy = "Project_ID"
    Me.OrderByOn = True
    Recordset.AddNew
    Recordset.Update
    Development_Site = GetDefaults("Site", 2)
    Production_Site = GetDefaults("Site", 2)
    Requery
    Recordset.MoveLast
    Me.AllowAdditions = False
    Me.txtCreatedBy.Value = VBA.Environ$("UserName")
    ShowData
    Exit_cmdAddNew_Click:
    Exit Sub
    Err_cmdAddNew_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddNew_Click
    End Sub


    Thanks!
    Dionna
    Attached Thumbnails Attached Thumbnails access_error.jpg  

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Can I ask what your intent with the code is (each step you want to perform)?

    Have you tried stepping through it with debug.print "I got to this point" type messages to find out where your code is breaking?

    My guess is that it's on the line

    recordset.update

    and I'm also guessing that you have some sort of index set up on your table to prevent duplicates on at least one field (though probably more?)

    Looks to me like you're trying to create a new record and populate 3 of the fields automatically but honestly, the order of them makes me wonder if that's actually what's going on.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 01-07-2014, 09:57 AM
  2. Replies: 3
    Last Post: 06-19-2013, 04:45 PM
  3. Replies: 12
    Last Post: 04-26-2012, 04:01 AM
  4. Replies: 4
    Last Post: 07-26-2011, 12:33 AM
  5. Access 2010 fails where 2007 worked
    By dick in forum Access
    Replies: 3
    Last Post: 10-16-2010, 01:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums