HM2K
HM2K

Reputation: 1511

How do I delete rows from an access database using a script?

I am trying to programmatically remove rows from a Microsoft Access Database using a script (such as vbscript or whs).

It looks like there are two or more engines that can be used to connect to an mdb file which are the ADO extension Jro.JetEngine or DAO.Database DBEngine.

In addition to this, there is a column in the table called CreatedDate which contains the date that the entry was created.

I plan to use this to remove entries that are older than N days old.

How would I achieve something like this?

Upvotes: 1

Views: 4197

Answers (1)

renick
renick

Reputation: 3881

You need something like this script.

connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & yourDatabase & ";"
sql = "delete from yourTable where CreateDate < " & yourDateString
set cn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")
cn.open connectionString
cmd.ActiveConnection = cn
cmd.CommandText = sql
cmd.execute
cn.Close

The specific connection string for your MS Access version can be had at connectionstrings.com

Upvotes: 1

Related Questions