Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / October 2005

Tip: Looking for answers? Try searching our database.

Compact & Repair - Access 2002

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex Martinez - 30 Oct 2005 06:09 GMT

Hi,

I want to have a command button that will do a "Compact & Repair" in my
form, but the problem is I don't know the coding.  If anybody can provide me
the coding I will appreicated.  Any tips or website to visit will be
appreicated.   Thank you.
Regards
Allan Murphy - 30 Oct 2005 06:02 GMT
Alex

You have two options

1. Compact on Close
   From the Toolbar select Tools ---> Option -----> General Tab then tick
Compact on close this compact the database when you exit the current
database.

2. Modify  the following code, this code compacts the back end of a database
that I have previously used via a command button or menu item

Sub CompactBE()
Dim OldMBD As String
Dim NewMBD As String
Dim MBDPath As String
Dim NewMDBFileNPath As String
Dim OldMDBFileNPath As String

Dim Msg, Style, Title, Response, MyString
Msg = "This option compacts the back end. It takes up to five minutes. Do
you want to continue ?"    ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2    ' Define buttons.
Title = "Compact Back End"    ' Define title.

Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then    ' User chose Yes.
   OldMBD = "DataHolder.mdb"
   DoCmd.Echo False, "Locating File. Please wait"
   MBDPath = "//Nsw-sit-1\Vol1\Data\rosters\"
   NewMBD = "DataHolderNew.mdb"

   OldMDBFileNPath = MBDPath & OldMBD
   NewMDBFileNPath = MBDPath & NewMBD
   DoCmd.Echo False, "Compacting BE. Please wait"
   DBEngine.CompactDatabase OldMDBFileNPath, NewMDBFileNPath
   DoCmd.Echo False, "Deleting old File. Please wait"
   Kill (OldMDBFileNPath)                      ' deletes the original file
   DoCmd.Echo False, "Renaming new File. Please wait"
   FileCopy NewMDBFileNPath, OldMDBFileNPath      ' copys the new to the
old
   DoCmd.Echo False, "Deleting temporary file. Please wait"
   Kill (NewMDBFileNPath)                 ' kills newpath
   MyString = "Process actioned."    ' Perform some action.
Else    ' User chose No.
   MyString = "Process abandoned"    ' Perform some action.
End If

MsgBox MyString
CompactBE_Exit:
Exit Sub
DoCmd.Echo True
CompactBE_Error:

Select Case Err
Case 3356
MsgBox "Other user currently blocking process. Try again later."
Case Else
MsgBox "Unknown error."
End Select
GoTo CompactBE_Exit

End Sub

Allan Murphy
Email: allanmurphy@unwired.com.au

> Hi,
>
[quoted text clipped - 3 lines]
> appreicated.   Thank you.
> Regards
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.