D
dchow
I have been using the following to query a database through ODBC:
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DATABASE=DB;
UID=user;PWD=password;DSN=sDSN, Destination:=Range("A1"), Sql:=sSQL)
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.PreserveColumnInfo = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
If sSQL is a SELECT, there is no problem. If it is a DELETE, I have to
set 'Refresh BackgroundQuery' to True. Otherwise I will get an
Application Defined or Object Defined error. What was wrong?
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DATABASE=DB;
UID=user;PWD=password;DSN=sDSN, Destination:=Range("A1"), Sql:=sSQL)
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.PreserveColumnInfo = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
If sSQL is a SELECT, there is no problem. If it is a DELETE, I have to
set 'Refresh BackgroundQuery' to True. Otherwise I will get an
Application Defined or Object Defined error. What was wrong?