• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Compacting database

I'm using VB6 pro edition.

I try to compact my Access-database every time when I close my program.
Way I tryed to do it:

CompactDatabase App.Path & "/database.mdb", App.Path & "/newdatabase.mdb"
.
.

But when I do this vb gives me an error:
sub of function not defined...

What could be wrong? I remember that I have used this method sometimes before without any problems...

Thanks in advance!
0
majala
Asked:
majala
  • 3
  • 3
  • 2
  • +1
1 Solution
 
cquinnCommented:
dbengine.compactdatabase
0
 
majalaAuthor Commented:
Now I got an error:
(after using dbengine.compactdatabase)

Run-time error '424':
Object required
0
 
pookytooCommented:
The function is part of DAO.
Reference DAO and VB will know the function.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
sbmcCommented:
Try using \ instead of /
0
 
majalaAuthor Commented:
Now I got an error which says that database is already open. I have DbGrid and Data controller in my form which is connected to that database. So I have close that connection before I can compact that database. How I close connection?
0
 
pookytooCommented:
   Dim db As String
    db = Data1.DatabaseName
    Data1.DatabaseName = ""
    Data1.Refresh
    DBEngine.CompactDatabase "olddb", "newdb"
    Data1.DatabaseName = db

where data1 is the name of your data controler.
0
 
pookytooCommented:
and refresh after setting back the databasename, of course.
That should save you.

0
 
majalaAuthor Commented:
I tryed that your way to close a database and I got that same error I described in a previous message. Anyway I tryed this:
Data1.Database.close

and it worked.

0
 
sbmcCommented:
Try using \ instead of /
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now