ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   An ODBC question (https://www.excelbanter.com/excel-programming/271112-odbc-question.html)

dchow

An ODBC question
 
I have been using the following to query a database through ODBC:

With ActiveSheet.QueryTables.Add(Connection:="ODBC;DATA BASE=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?


All times are GMT +1. The time now is 12:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com