ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   sql to database (https://www.excelbanter.com/excel-programming/439066-sql-database.html)

Bre-x

sql to database
 
Hi,
On MS Excell using VBA, I would like to send a sql command to and MS Access
database

"delete * from mytable where id=89"

Thank you all!!!!



goshute

sql to database
 
Try This:

Create two objects in Access.
1. A Query that deletes the records from the table.
2. A Macro that runs the query.

In Excel VBA Editor:
1. add a reference to your version of Access.
2. Inset this code that will start a new instance of Access and run
the macro

Sub RunAccessQuery()
Dim appAccess As Access.Application
Set appAccess = New Access.Application
appAccess.Visible = True
appAccess.DoCmd.SetWarnings False
appAccess.OpenAccessProject ("C:\Test.mdb")
appAccess.DoCmd.RunMacro ("MacroToDeleteRecordsWith89")
appAccess.DoCmd.SetWarnings True
appAccess.Quit
Set appAccess = Nothing
End Sub

I did not test code, so be sure to test on a test application.

Goshute

Bre-x

sql to database
 
Thank you!!




All times are GMT +1. The time now is 03:44 AM.

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