+ Reply to Thread
Results 1 to 8 of 8

ADODB Record Upate

Hybrid View

  1. #1
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: ADODB Record Upate

    Try this


              If Not .EOF Then '<== ' Unique Id exists
                 
                '.Fields("Job Number") = Range("A" & r).Value 'Unique key
                .Fields("Inspection Date") = Range("B" & r).Value
                .Fields("SHIP DATE") = Range("C" & r).Value
               
                .Update ' stores the new record 
                
              Else '<== Unique id does not exist
                
                .AddNew ' add values to each field in the record
                .Fields("Job Number") = Range("A" & r).Value 'Unique key
                .Fields("Inspection Date") = Range("B" & r).Value
                .Fields("SHIP DATE") = Range("C" & r).Value
                .Update
              End If
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  2. #2
    Registered User
    Join Date
    09-05-2012
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: ADODB Record Upate

    Mike,

    I made a mistake. I've tried your method in your last reply. If I add .Update before the 'end if' it throws a Run-time error -214217887 (80040e21) - "The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index or redefine the index to permit duplicate entries and try again."

  3. #3
    Registered User
    Join Date
    09-05-2012
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: ADODB Record Upate

    Mike,

    I've had some time to play with the code. For some reason the EOF if statement is skipped even if the record exists. Any ideas?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1