|
-
Jun 4th, 2000, 05:02 PM
#1
Thread Starter
New Member
Does anyone know how to purge the data in the database from visual basic.
-
Jun 4th, 2000, 05:39 PM
#2
PowerPoster
Delete unused record and compact the database
Assume you're using MS Access database and...
- Old Databsse = your current database name.
- New Database = your temp database name.
- TblMyTable= the Table inside your current database.
Code:
Screen.MousePointer = vbHourglass
Dim Db As DAO.Database
Set Db = DBEngine.Workspaces(0).OpenDatabase("<Old Database>", False, False)
'Purge the unused record.
Db.Execute "DELETE * FROM TblMytable;"
Db.Close
Set Db = Nothing
DBEngine.CompactDatabase "<Old Database>", "<New Database>", dbLangGeneral
'Delay 3sec for the computer to catch up.
Sleep 3000
'Delete the current database
If Dir("<Old database>") <> "" Then Kill "<Old Database>"
'Rename the temp databse to the original database name.
Name "<New Databse>" As "<Old Databse>"
Screen.MousePointer = vbDefault
[Edited by Chris on 06-05-2000 at 02:43 PM]
-
Jun 4th, 2000, 06:50 PM
#3
Thread Starter
New Member
Re: Delete unused record and compact the database
Originally posted by Chris
Assume you're using MS Access database and...
- Old Databsse = your current database name.
- New Database = your temp database name.
- TblMyTable= the Table inside your current database.
Code:
Screen.MousePointer = vbHourglass
Dim Db As DAO.Database
Set Db = DBEngine.Workspaces(0).OpenDatabase("<Old Database>", False, False)
'Purge the unused record.
Db.Execute "DELETE * FROM TblMytable;"
Db.Close
Set Db = Nothing
DBEngine.CompactDatabase "<Old Database>", "<New Database>", dbLangGeneral
'Delay 3sec for the computer to catch up.
Sleep 3000
'Delete the current database
If Dir("<Old database>") <> "" Then Kill "<Old Database>"
'Rename the temp databse to the original database name.
Name "<New Databse>" As "<Old Databse>"
Screen.MousePointer = vbDefault
[Edited by Chris on 06-05-2000 at 02:43 PM]
Chris,
It doesnt seem to work. An error occur in the line "Kill "<Old Database>"". It say permission denied. So any idea about that.
-
Jun 5th, 2000, 07:26 AM
#4
PowerPoster
Does you close all the DAO object or any others application is open the "<Ols Database>"?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|