ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SQL Delete Record using Excel VBA (https://www.excelbanter.com/excel-programming/410973-sql-delete-record-using-excel-vba.html)

Steve

SQL Delete Record using Excel VBA
 
I have no problem reading, writing and counting from a table using this VBA /
SQL connection, but when I try to delete a record it does nothing. Any
suggestions would be welcome. Sometimes I get nothing, but lately I've been
getting a 1004 'General ODBC error.'



Thanks, Steve


Here's my code:
Dim SH As Object
Set SH = Sheet1
With SH.Range("Query_from_Loewenpr").QueryTable
.Connection = "ODBC;DSN=loewenpr;"
.CommandText = Array( _
"DELETE FROM DBPR.DHXSLRTLIB.DHLOC " & _
"WHERE DHLOC.BUSINESS_UNIT = '" & "DHTEST" & _
"')" _
)
.BackgroundQuery = False
.Refresh BackgroundQuery:=False
End With


All times are GMT +1. The time now is 09:41 AM.

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