Mike,
I finally have played with the code a little. I get a Run-time error 3219. 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." Where am I going wrong? Here is my code below:
db.Open
Set rs = New ADODB.Recordset
rs.Open "Select [Job Number], [Inspection Date], [SHIP DATE] " & _
"From FinalInspection " & _
"Where((([Job Number])= '1'));", db, adOpenDynamic, adLockOptimistic '< '1' for text field in where clause
'< 1 for numeric field in where clause
'rs.Open "FinalInspection", db, adOpenDynamic, adLockOptimistic
r = 2 ' the start row in the worksheet
With rs
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
End If
.Close
End With
Set rs = Nothing
db.Close
End Sub
Bookmarks