A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

compact database without opening it



 
 
Thread Tools Display Modes
  #1  
Old July 7th, 2008, 08:23 PM posted to microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.gettingstarted,microsoft.public.access.modulesdaovba,microsoft.public.access.multiuser
Rocky5
external usenet poster
 
Posts: 7
Default compact database without opening it

I had this code that worked okay in prior access versions

What do I need to cahnge to make it work in access 2003 and in 2007? See
Below:
also how do I put in a browse button so I can go find it. I have inherited
this code, and I am a beginner.

Is there a way to put a timer on it and make it do it at night when there
are no users in it?

Thank so much in advance



Private Sub Command0_Click()
On Error GoTo Err_Command0_Click


Dim dbCodename As Variant
Dim dbdataname As Variant
Dim dbcodebak As Variant
Dim dbdatabak As Variant
dbCodename = "location of database or path to it goes here"
'dbCodename = "P:\92\database\my.mdb"
'dbdataname = "P:\92\database\my_data2000.mdb"
DoEvents
DoCmd.Hourglass True
FileCopy dbCodename, Left(dbCodename, Len(dbCodename) - 3) & "bak"
'FileCopy dbdataname, Left(dbdataname, Len(dbdataname) - 3) & "bak"
DoEvents
DoCmd.Hourglass False
MsgBox " Please wait for Database Repair...", vbQuestion, "Microsoft Access"
DoCmd.Hourglass True
DBEngine.RepairDatabase Left(dbCodename, Len(dbCodename) - 3) & "bak"
'DBEngine.RepairDatabase Left(dbdataname, Len(dbdataname) - 3) & "bak"
DoCmd.Hourglass False
MsgBox " Successufully Repaired Database!!" & Chr(13) & " Starting database
Compact now....", vbInformation
DoCmd.Hourglass True
DoEvents
Kill dbCodename
'Kill dbdataname
DoEvents
DBEngine.CompactDatabase Left(dbCodename, Len(dbCodename) - 3) & "bak",
dbCodename
'DBEngine.CompactDatabase Left(dbdataname, Len(dbdataname) - 3) & "bak",
dbdataname
'MsgBox " Compact Completed Successfully@@", vbExclamation, " All Done"
dbcodebak = Left(dbCodename, Len(dbCodename) - 3) & "bak"
'dbdatabak = Left(dbdataname, Len(dbdataname) - 3) & "bak"
Kill dbcodebak
'Kill dbdatabak
DoCmd.Hourglass False
MsgBox " Database Repair and Compact Completed Successfully!!",
vbExclamation, "Operation Complete"

Exit_Command0_Click:
Exit Sub

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click

End Sub


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:47 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.