Macro

Reai1979
07-16-2001, 09:31 AM
Another question: Is it possibly to run a macro in a database externally , ie through VB ? I'm designing an .exe through VB that copies and compacts the database, but I need to clear out the tables in the database. Currently I'm using SQL.

littlebigman_uk
07-17-2001, 07:25 AM
It would be better if you connected to the database externally and cleared it after it has been copied.

dim rs as recordset
dim db as database
set db=opendatabase("dbname.mdb")
set rs=db.openrecordset("tblname")
do while not rs.eof
if not rs.eof then rs.movelast
rs.delete
loop
rs.close
db.close

or something like that.

Reai1979
07-17-2001, 07:33 AM
Thanks for the suggestion! I used SQL statements but a loop definitely cuts down on coding!

jerryfchui
07-17-2001, 06:14 PM
I thought clearing a table using sql statement could be simpler, why not? I will have something like this:

Dim db As Database
Dim sqlStatement As String

Set db = OpenDatabase("d:\misc\myDb.mdb")
sqlStatement = "delete * from myTable"
db.Execute (sqlStatement)
db.Close
set db = nothing

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum