JumboCactuar
Well-known Member
- Joined
- Nov 16, 2016
- Messages
- 788
- Office Version
- 365
- Platform
- Windows
Hi,
not sure if this fits into the excel category but its what im using with ADODB
With the above, if the table already contains the IDNO, i instead want to UPDATE the existing record
I know i can probably do an SQL select on the IDNO then if anything is returned then update, just wondering if theres a better way
not sure if this fits into the excel category but its what im using with ADODB
Code:
Sub insertSQL()
Application.ScreenUpdating = False
var1 = Sheets("Sheet2").Range("A1")
Set cnn = CreateObject("ADODB.Connection")
cnn.Open MyConn
Rw = 2
For i = 2 To Rw
val1 = Cells(i, 1).Value
val2 = Cells(i, 2).Value
val3 = Cells(i, 3).Value
val4 = Cells(i, 4).Value
val5 = Cells(i, 5).Value
val6 = Cells(i, 6).Value
MYSQL = "INSERT INTO umtykbfw_test.`TABLE 1` (Country,IDNO,Yr_2000,Yr_2015,Yr_2025,Yr_2050) VALUES ('" & val1 & "','" & val2 & "','" & val3 & "','" & val4 & "','" & val5 & "','" & val6 & "');"
cnn.Execute MYSQL
Next i
cnn.Close
Set cnn = Nothing
Application.ScreenUpdating = True
End Sub
With the above, if the table already contains the IDNO, i instead want to UPDATE the existing record
I know i can probably do an SQL select on the IDNO then if anything is returned then update, just wondering if theres a better way