Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 30th, 2007, 02:38 PM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compact Access Database

 I have a large access database that has to be compacted frequently. I have tried to use the compact database functionality available in access however it takes too long to do it this way. What i would like to have is another access database that can compact the larger database. I have tried using visual basic code to do this, it didn't seem to work. I kept getting a pop-up that asked me for a macro. My knowledge of VB is quite limited, can anyone help me out with this.
This is what i tried to do:

1. Created a new database
2. Created a new module
3. Pasted in following code:
Sub Main()
        Try
            Dim File_Path, compact_file As String
            'Original file path that u want to compact
            File_Path = AppDomain.CurrentDomain.BaseDirectory & "E:\new finance backup(hold shift).mdb"
            'compact file path, a temp file
            compact_file = AppDomain.CurrentDomain.BaseDirectory & "E:\test_1.mdb"
            'First check the file u want to compact exists or not
            If File.Exists(File_Path) Then
                Dim db As New DAO.DBEngine()
                'CompactDatabase has two parameters, creates a copy of compact DB at the Destination path
                db.CompactDatabase(File_Path, compact_file)
            End If
            'restore the original file from the compacted file
            If File.Exists(compact_file) Then
                File.Delete (File_Path)
                File.Move(compact_file, File_Path)
            End If
        Catch ex As Exception
            MsgBox (ex.Message)
        End Try
    End Sub
4. I seem to be obtaining compile errors.

Any help will be appreciated !






Similar Threads
Thread Thread Starter Forum Replies Last Post
Compact and Repair Access Database raguapk VB How-To 8 May 23rd, 2013 10:00 AM
Compact Access Database tang_moor VB Databases Basics 1 February 10th, 2007 04:10 PM
Compact And Repair Access Database myedu2k4 Pro VB Databases 1 May 25th, 2004 01:43 AM
Compact Access Database lai_ccca Access VBA 0 January 9th, 2004 08:41 PM
compact access database hellobookus Access VBA 2 January 5th, 2004 06:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.