Solved

Compacting database

Posted on 2000-03-01
9
192 Views
Last Modified: 2012-05-04
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
Comment
Question by:majala
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 15

Expert Comment

by:cquinn
Comment Utility
dbengine.compactdatabase
0
 

Author Comment

by:majala
Comment Utility
Now I got an error:
(after using dbengine.compactdatabase)

Run-time error '424':
Object required
0
 
LVL 1

Accepted Solution

by:
pookytoo earned 50 total points
Comment Utility
The function is part of DAO.
Reference DAO and VB will know the function.
0
 
LVL 2

Expert Comment

by:sbmc
Comment Utility
Try using \ instead of /
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:majala
Comment Utility
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
 
LVL 1

Expert Comment

by:pookytoo
Comment Utility
   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
 
LVL 1

Expert Comment

by:pookytoo
Comment Utility
and refresh after setting back the databasename, of course.
That should save you.

0
 

Author Comment

by:majala
Comment Utility
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
 
LVL 2

Expert Comment

by:sbmc
Comment Utility
Try using \ instead of /
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now