MySQL Forums
Forum List  »  MySQL for Excel

Update record if exists else insert.
Posted by: Paul Keddie
Date: October 11, 2019 10:23AM

Hi there

I use this code to update a record:

Dim rst As New ADODB.Recordset, x As Long
With rst
.Open "SELECT * FROM ActJobs WHERE JobNo=" & frmd.Cells(2, 19), _
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=K:\KKDB.accdb", adOpenDynamic, adLockOptimistic
For x = 0 To 38
If x = 17 Or x = 20 Or x = 23 Then
If frmd.Cells(2, x + 3) <> "" Then
.fields(x) = DateValue(frmd.Cells(2, x + 3))
End If
Else
If x = 24 And frmd.Cells(2, x + 3) = "" Then frmd.Cells(2, x + 3) = 0
If x = 25 And frmd.Cells(2, x + 3) = "" Then frmd.Cells(2, x + 3) = 0
If x = 26 And frmd.Cells(2, x + 3) = "" Then frmd.Cells(2, x + 3) = 0
.fields(x) = frmd.Cells(2, x + 3)
End If
Next
.Update
.Close
End With

However, some JobNo's have been accidentally deleted and so I would like to insert the data if the JobNo doesn't exist.

Any pointers please?

Thanks in advance

Options: ReplyQuote


Subject
Views
Written By
Posted
Update record if exists else insert.
1555
October 11, 2019 10:23AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.