Hello All,
I was wondering if anyone had ever experienced this.
When ever I use my DB, it continues to get larger. Is there away to automatically compact the database upon closing or opening? Any help would be greatly apprecited.
If you need some more information, please let me know.
53 4764
In the Access Database window go to the tools menu then Options Click the general tab and click on Compact on Close. I can also show you how it can be done in code if you would like.
You might check out the possibility of adding compact on the right click menu when your in explorer. Right Click Compact menu
Thanks for the quick response. Would you mind showing me how to do this with code. I can not seem to find that option in my options tab selections. I am using access 97
Well i'll be i have a whole slew of DB's here that i am managing and I thought for sure it was in one of them evidently not. must be in some of my older work. I did find it in VBS but that won't help in VBA. Anyhow here is a snippet I am sure you can run with this. -
DoCmd.CopyDatabaseFile strDbName, True, True
-
DBEngine.CompactDatabase strDbName, strTempDB
-
I tried this snippet before. But it can only be used on a DB you are not currently in. I need someway to compact on closing. Any thoughts on this? I will keep looking for compact on close.
O.K. I use VBA to create a VBS script and call it for updating my clients Front Ends the following code should help you accomplish what you need. Note this was stripped out of my DB so some of it may not be needed. -
Option Compare Database
-
Option Explicit
-
Private Declare Function apiShellExecute Lib "shell32.dll" _
-
Alias "ShellExecuteA" _
-
(ByVal hwnd As Long, _
-
ByVal lpOperation As String, _
-
ByVal lpFile As String, _
-
ByVal lpParameters As String, _
-
ByVal lpDirectory As String, _
-
ByVal nShowCmd As Long) _
-
As Long
-
Public Const WIN_NORMAL = 1 'Open Normal
-
Private Const ERROR_SUCCESS = 32&
-
Private Const ERROR_NO_ASSOC = 31&
-
Private Const ERROR_OUT_OF_MEM = 0&
-
Private Const ERROR_FILE_NOT_FOUND = 2&
-
Private Const ERROR_PATH_NOT_FOUND = 3&
-
Private Const ERROR_BAD_FORMAT = 11&
-
-
-
Sub CompactSub()
-
'Define strPath and strFName and declare all variables
-
-
RunIt strPath, strFName
-
DeleteIt strFName
-
DoEvents
-
DBEngine.Idle
-
Application.Quit
-
End Function
-
Sub RunIt(strPath As String, strFName As String)
-
Dim varRet
-
varRet = fHandleFile(strPath & strFName, WIN_NORMAL)
-
End Sub
-
Function DeleteIt(strFile)
-
Dim FSO, strErr As String
-
Set FSO = CreateObject("Scripting.FileSystemObject")
-
strErr = FSO.DeleteFile(strFile)
-
'If strErr > 0 Then
-
' WS.PopUp strErr, 3
-
'End If
-
Set FSO = Nothing
-
End Function
-
-
Function fHandleFile(stFile As String, lShowHow As Long)
-
Dim lRet As Long, varTaskID As Variant
-
Dim stRet As String
-
'First try ShellExecute
-
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
-
stFile, vbNullString, vbNullString, lShowHow)
-
-
If lRet > ERROR_SUCCESS Then
-
stRet = vbNullString
-
lRet = -1
-
Else
-
Select Case lRet
-
Case ERROR_NO_ASSOC:
-
'Try the OpenWith dialog
-
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
-
& stFile, WIN_NORMAL)
-
lRet = (varTaskID <> 0)
-
Case ERROR_OUT_OF_MEM:
-
stRet = "Error: Out of Memory/Resources. Couldn't execute!"
-
Case ERROR_FILE_NOT_FOUND:
-
stRet = "Error: File not found. Couldn't Execute!"
-
Case ERROR_PATH_NOT_FOUND:
-
stRet = "Error: Path not found. Couldn't Execute!"
-
Case ERROR_BAD_FORMAT:
-
stRet = "Error: Bad File Format. Couldn't Execute!"
-
Case Else:
-
End Select
-
End If
-
fHandleFile = lRet & _
-
IIf(stRet = "", vbNullString, ", " & stRet)
-
End Function
-
Thanks I will look at this and see if I can not get it to work for me. If I do, I will post what I used.
VBS Code again this was stripped out of a bunch of other code and other code was stripped from this so this is definately not a copy paste solution but should get you headed in the right direction. Remember though VBS does not handle errors well: -
Sub CompactMe()
-
on error resume next
-
Set objAccess = WScript.CreateObject("Access.Application")
-
Set objScript= WScript.CreateObject("Scripting.FileSystemObject")
-
objScript.CopyFile strDBName , strDBName & "z", True
-
If Err.Number <> 0 Then
-
myD=Err.Number & " " & Err.Description & vbcrlf & "Creating a copy of the Database: " & strDBName
-
WS.Popup myD, 3
-
err.Clear
-
WScript.Quit()
-
End If
-
objAccess.DbEngine.CompactDatabase strDBName ,strTempDB
-
If Err.Number <> 0 Then
-
myD=Err.Number & " " & Err.Description & vbcrlf & "Database Name:" & strDBName & vbcrlf & "Temp Database for Compacting:" & strTempDB & vbcrlf & "line 174 Compacting the database subroutine."
-
WS.Popup myD, 3
-
err.Clear
-
WScript.Quit()
-
End If
-
If objScript.FileExists(strDBName) Then
-
objScript.DeleteFile strDBName
-
End If
-
objScript.CopyFile strTempDB, strDBName, True
-
If Err.Number <> 0 Then
-
myD=Err.Number & " " & Err.Description & vbcrlf & "Database Name:" & strDBName & vbcrlf & "Temp Database for Compacting:" & strTempDB & vbcrlf & "line 174 Compacting the database subroutine."
-
WS.Popup myD, 3
-
EmailErr(Err.Number & " " & Err.Description & vbcrlf & "Database Name:" & strDBName & vbcrlf & "New Database after Compacting:" & strTempDB & vbcrlf & "line 181 Compacting the database subroutine.")
-
err.Clear
-
WScript.Quit()
-
End If
-
objScript.DeleteFile strTempDB
-
Set objScript = Nothing
-
If Err.Number <> 0 Then
-
myD=Err.Number & " " & Err.Description & vbcrlf & "Database Name:" & strDBName & vbcrlf & "Temp Database for Compacting:" & strTempDB & vbcrlf & "line 174 Compacting the database subroutine."
-
WS.Popup myD, 3
-
WScript.Quit()
-
End If
-
myD="The second stage to this script is to make sure the tables are relinked!" & vbcrlf & vbcrlf & "Please be patient!"
-
WS.Popup myD, 3
-
dbs.close
-
objAccess.quit 2
-
set objAccess = Nothing
-
Set dbs = nothing
-
Set wks = Nothing
-
set dao=nothing
-
If Err.Number <> 0 Then
-
WScript.Quit()
-
End If
-
End Sub
-
strTempDb, and the other names, could you give me a break down of what those should be? I would really appreciate it.
strDBName ,strTempDB
strDBName is your database name
strTempDB merely a temporary db which will be deleted using the script. -
Path = GetPath
-
strTempDB = Path & "Comp0001.mde"
-
strDBName = Path & "MyMDE.mde"
-
Function GetPath
-
' Return path to the current script
-
path = WScript.ScriptFullName ' script file name
-
GetPath = Left(path, InstrRev(path, "\"))
-
End Function
-
The above Function only works if it is in the same directory as the database.
My version of access does not recognize WSscript. and what is this vbcrlf Thanks again
Sorry the following should be in the VBS script: -
Path = GetPath
-
'Temporary db to be deleted once Compact is complete
-
strTempDB = Path & "Comp0001.mde"
-
'Your .mdb or mde file name here
-
strDBName = Path & "MyMDE.mde"
-
-
Function GetPath
-
' Return path to the current script
-
path = WScript.ScriptFullName ' script file name
-
GetPath = Left(path, InstrRev(path, "\"))
-
End Function
-
I am not sure I know what that means.
NeoPa 32,534
Expert Mod 16PB
I tried this snippet before. But it can only be used on a DB you are not currently in. I need someway to compact on closing. Any thoughts on this? I will keep looking for compact on close.
Compact on Close was introduced in the next version (2K) :( vbCrLf is a predefined string within VBA which is just a Carriage-Return / Line-Feed sequence.
As denburt says, the ability to Compact your current database depends on getting out of it first - hence his idea to use VBScript.
When I post the second item from your post: -
Path = GetPath
-
strTempDB = Path & "Comp0001.mde"
-
strDBName = Path & "MyMDE.mde"
-
Function GetPath()
-
' Return path to the current script
-
Path = WScript.ScriptFullName ' script file name
-
GetPath = Left(Path, InstrRev(Path, "\"))
-
End Function
-
I get an error when I compile that says invalid outside procedure. Where should I put this exactly, does it matter what I call the module?
Also the .mde, is that the same as .mdb. which should I use?
I just now realized that I should paste -
Path = GetPath
-
strTempDB = Path & "Comp0001.mde" ...
in a seperate script file, because that is what you said to do, and I just did not listen, oops. Sorry. Does it matter what I call it?
Also when I compile my Form code, it does not recognize wscript. any thoughts?
That snippet of code should be in your VBS script not the database. Make sure the database and script are in the same location or that function will not work as expected. See this post
Your database can be either a mdb or mde. When you are in an MDB you can create an MDE which is simply creating a copy of your database that is completely compiled a little quicker and your users can't go into the code.
Your database can be either a mdb or mde. When you are in an MDB you can create an MDE which is simply creating a copy of your database that is completely compiled a little quicker and your users can't go into the code.
Ok thanks. Any ideas about WScript?
Also when I compile my Form code, it does not recognize wscript. any thoughts?
Placing it in the database instead of the VBS file and that will happen. :) please see my previous post.
Placing it in the database instead of the VBS file and that will happen. :) please see my previous post.
Dang, I am sorry about that. So maybe I will post some questions I have now.
When I compile the module it has a problem with this line
RunIt strPath, strFName
Does i matter what I call the .vbs file, I am sure it does. But I can not figure out where the module would call it.
How do I get this to run, I am guessing I will make it a on close event, but any input on the code to use would be awesome.
Thanks Again for the help.
You can call the VBS file anything you want just make sure you establish this in the variable in your database.
'Define strPath and strFName and declare all variables
strPath = Application.CurrentProject.Path
strFname = "YourVBSFileName.vbs"
-
strPath = Application.CurrentProject.Path
-
Can you break this down for me. Currentproject is not an option that my version recognizes, nor is Path
O.K. been a while since I was in 97.
strPath = "C:\YourFolderWhereDBResides"
:)
Thanks,
how should the strPath amd strFName be declared as String or what?
I am now getting an error that reads,
byRef argument type mismatch any thoughts
how should the strPath amd strFName be declared as String or what?
Yes for both.
I am now getting an error that reads,
byRef argument type mismatch any thoughts
Do you get a button to debug when you get that error? If so what line does it highlight?
Yes for both.
Do you get a button to debug when you get that error? If so what line does it highlight?
where strPath is highlighted
-
Sub CompactSub()
-
'Define strPath and strFName and declare all variables
-
Dim strPath, strFName As String
-
-
strPath = "C:\Documents and Settings\laoxb\Desktop\FalconAnalysis.mdb"
-
strFName = "Test.vbs"
-
-
RunIt strPath, strFName
-
DeleteIt strFName
-
DoEvents
-
DBEngine.Idle
-
Application.Quit
-
End Function
-
This is the block in question now.
Is strFName = "NewText.vbs" or whatever your vbs file is named and are they both in the same folder?
Hello All,
I was wondering if anyone had ever experienced this.
When ever I use my DB, it continues to get larger. Is there away to automatically compact the database upon closing or opening? Any help would be greatly apprecited.
If you need some more information, please let me know.
If all else fails, why not use a Batch File either as a Shortcut on the Desktop or as a Scheduled Task. Here are the contents of Compact.bat - @echo off
-
cls
-
cd\Program Files\Microsoft Office\OFFICE11
-
MSACCESS.EXE /compact C:\Test_Directory\Employees.mdb
Is strFName = "NewText.vbs" or whatever your vbs file is named and are they both in the same folder?
They are both on the Desktop currently
If all else fails, why not use a Batch File either as a Shortcut on the Desktop or as a Scheduled Task. Here are the contents of Compact.bat - @echo off
-
cls
-
cd\Program Files\Microsoft Office\OFFICE11
-
MSACCESS.EXE /compact C:\Test_Directory\Employees.mdb
Can you explain how to implement this tool Adezii? Thanks for the extra inpout
O.K. i created a new database and tested it. I did need to make a couple of minor adjustments but it is working. You are using Access 97 so there may be an issue there but I don't think there should be.
I commented out the delete line (it can be removed):
The Runit line should be O.K.
strPath = "C:\Documents and Settings\denburt\Desktop"
StrFName = "NewText.vbs"
RunIt strPath, StrFName
'DeleteIt StrFName
In the VBS script file make sure you adjust the following lines to suite your needs:
strTempDB = Path & "Comp0001.mdb"
strDBName = Path & "MenuButtons.mdb"
Also in the VBS script file I added:
CompactMe()
Right before the following line:
Sub CompactMe()
I hope this does the trick for you.
LOL thanks Adezii as usual I have obviously made this more complicated than it needed to be.
LOL thanks Adezii as usual I have obviously made this more complicated than it needed to be.
Is ADezii's solution easier? I can not get the module to compile still
NeoPa 32,534
Expert Mod 16PB
Chase, do you know anything about : - Batch (Command) files?
- The AT scheduler?
Chase, do you know anything about :- Batch (Command) files?
- The AT scheduler?
Batch Files. no
AT yes.
Is ADezii's solution easier? I can not get the module to compile still
Still debugs on the same line?
Still debugs on the same line?
Yes, I have tried commenting it out, but then more errors occur.
O.K. reviewing previous posts. - Sub CompactSub()
-
'Define strPath and strFName and declare all variables
-
Dim strPath, strFName As String
-
-
strPath = "C:\Documents and Settings\laoxb\Desktop"
-
strFName = "Test.vbs"
-
-
RunIt strPath, strFName
-
DeleteIt strFName
-
DoEvents
-
DBEngine.Idle
-
Application.Quit
-
End Function
Remove the "\FalconAnalysis.mdb" from your strPath This is how it should look.
O.K. reviewing previous posts. - Sub CompactSub()
-
'Define strPath and strFName and declare all variables
-
Dim strPath, strFName As String
-
-
strPath = "C:\Documents and Settings\laoxb\Desktop"
-
strFName = "Test.vbs"
-
-
RunIt strPath, strFName
-
DeleteIt strFName
-
DoEvents
-
DBEngine.Idle
-
Application.Quit
-
End Function
Remove the "\FalconAnalysis.mdb" from your strPath This is how it should look.
I am still getting the same error.
Are you sure you have all the code in that module that you should have.
I noticed when I reposted I had that stupid delete statement in there again my apologies. If we can get the RunIt function to cooperate then the rest should be easy. -
Sub CompactSub()
-
Dim strPath As String, StrFName As String
-
strPath = "C:\Documents and Settings\denburt\Desktop"
-
StrFName = "NewText.vbs"
-
RunIt strPath, StrFName
-
DoEvents
-
DBEngine.Idle
-
Application.Quit
-
End Sub
-
BTW Adezi's code is for the external file which we are not able to run until we get this RunIt issue worked out.
Is the error still the same?
byRef argument type mismatch
Are you sure you have all the code in that module that you should have.
I noticed when I reposted I had that stupid delete statement in there again my apologies. If we can get the RunIt function to cooperate then the rest should be easy. -
Sub CompactSub()
-
Dim strPath As String, StrFName As String
-
strPath = "C:\Documents and Settings\denburt\Desktop"
-
StrFName = "NewText.vbs"
-
RunIt strPath, StrFName
-
DoEvents
-
DBEngine.Idle
-
Application.Quit
-
End Sub
-
BTW Adezi's code is for the external file which we are not able to run until we get this RunIt issue worked out.
Is the error still the same?
byRef argument type mismatch
Yes it is the same error message
I have been messing around with the Batch file idea and came up with this. -
@echo off
-
cls
-
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" %1 /compact /repair "C:\Documents and Settings\laoxb\Desktop\FalconAnalysis.mdb"
-
Which works, but it prompts me in the access window to say ok, I want to supress that message box, any ideas on this tanget?
I have been messing around with the Batch file idea and came up with this. -
@echo off
-
cls
-
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" %1 /compact /repair "C:\Documents and Settings\laoxb\Desktop\FalconAnalysis.mdb"
-
Which works, but it prompts me in the access window to say ok, I want to supress that message box, any ideas on this tanget?
I cannot understand why you are getting a prompt in the Access Window, the Batch File works fine on my System. What exactly does the prompt say and what Version of Access are you working with? What is the purpose of the Replaceable Parameter (%1)?
NeoPa 32,534
Expert Mod 16PB
I have been messing around with the Batch file idea and came up with this. -
@echo off
-
cls
-
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" %1 /compact /repair "C:\Documents and Settings\laoxb\Desktop\FalconAnalysis.mdb"
-
Which works, but it prompts me in the access window to say ok, I want to supress that message box, any ideas on this tanget?
You could try using the /nostartup parameter. Otherwise I'm not sure there is an option to suppress :(
NeoPa 32,534
Expert Mod 16PB
I cannot understand why you are getting a prompt in the Access Window, the Batch File works fine on my System. What exactly does the prompt say and what Version of Access are you working with? What is the purpose of the Replaceable Parameter (%1)?
In Batch (.Bat) or Command (.Cmd) files, %1 represents the first parameter passed to the Batch/Command file.
NeoPa 32,534
Expert Mod 16PB
I have been messing around with the Batch file idea and came up with this. -
@echo off
-
cls
-
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" %1 /compact /repair "C:\Documents and Settings\laoxb\Desktop\FalconAnalysis.mdb"
-
Which works, but it prompts me in the access window to say ok, I want to supress that message box, any ideas on this tanget?
Chase,
You need to supply the name (of your Access db file) in the %1 variable or drop that and put the full path in its place.
The /compact & /repair parameters work on the preceding filename.
Chase,
You need to supply the name (of your Access db file) in the %1 variable or drop that and put the full path in its place.
The /compact & /repair parameters work on the preceding filename.
Thanks, I got it working the other day.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Charles McCaffery |
last post by:
I have written a database with auto-numbering and now wish to remove alkl of
my test data and set the auto-numbering back to one. How do I do this
please?
Charles McCaffery.
|
by: Corepaul |
last post by:
I am new to Access 2000. My operating system is Windows 2000.
In the early stage of development I noticed something weird. On my form, I have
a Command Button named "btnAlbumUp". The first time...
|
by: Willem |
last post by:
Based on MK's TSI_SOON (http://www.trigeminal.com/)I've created a
nifty little procedure that - whenever you compact you db you get an
incremental backup copy.
Given that you have a table with...
|
by: John Baker |
last post by:
Hi:
I know this is a strange question, but I have inherited a system where files are copied
and records re auto numbered (as an index field) )frequently, and I am wondering how high
the number...
|
by: trueblue7 |
last post by:
I apologize if this question has been asked before...
I'm trying to reset autonumber fields back to 1. The autonumber fields are
part of the composite primary keys.
I followed the MS help with...
|
by: SQL Server |
last post by:
Hi,
The tempdb file on one of our servers grew very large and used all
available disk space. This is SQL Server 2000 SP4. I have installed
hotfix version 8.00.2187. I opened a profiler trace but...
|
by: deepak |
last post by:
Hi All,
In C I heard the stack grows from top to bottom and heap from bottom to
top.
Is it compiler depend?
|
by: Wayne L |
last post by:
Ok now everyone has mentioned not to use auto number if it means anything to the user. My application uses the auto number for exporting only. I append the mastertbl column with my starting number of...
|
by: Fiddler2 |
last post by:
I noticed that after running compact/repair, I have to recompile my code for the program not to break the next time I open it. What happens is the auto exec macro runs the main() module, then hangs...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| | |