F
Fred
I have an ODBC driver to access a database but I can't figure out how to run
an UPDATE statement from Excel VBA.
I can create a query to return data and below is the recorded macro which
works fine and so shows that I can connect to the database OK.
So, how would I change this to run a simple UPDATE statement like
"UPDATE root.CLNDR CLNDR SET CLNDR.YN='Y'
WHERE CLNDR.DATE_=20041001;"
Sub Macro1()
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN=TIMS.udd;", _
Destination:=Range("A1"))
.Sql = Array("SELECT CLNDR.DATE_, CLNDR.DAY, " & _
"CLNDR.NUMA, CLNDR.NUMB, CLNDR.YN" & vbCrLf & _
"FROM root.CLNDR CLNDR")
.FieldNames = True
.RefreshStyle = xlInsertDeleteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SavePassword = True
.SaveData = True
End With
End Sub
Thanks
Fred
an UPDATE statement from Excel VBA.
I can create a query to return data and below is the recorded macro which
works fine and so shows that I can connect to the database OK.
So, how would I change this to run a simple UPDATE statement like
"UPDATE root.CLNDR CLNDR SET CLNDR.YN='Y'
WHERE CLNDR.DATE_=20041001;"
Sub Macro1()
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN=TIMS.udd;", _
Destination:=Range("A1"))
.Sql = Array("SELECT CLNDR.DATE_, CLNDR.DAY, " & _
"CLNDR.NUMA, CLNDR.NUMB, CLNDR.YN" & vbCrLf & _
"FROM root.CLNDR CLNDR")
.FieldNames = True
.RefreshStyle = xlInsertDeleteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SavePassword = True
.SaveData = True
End With
End Sub
Thanks
Fred