473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Compessing an Access database

Hi:

I have read a number of threads on the issue of compressing (compacting) Access data bases
programmatically, and have been left confused. We are using Access 2000, and I need code
that will programmatically compress an open database. (called "InvoiceManagement.be).

Can someone give me a piece of code that will do this, or a pointer to one, please?

Thanks

John Baker
Mar 14 '06 #1
12 2168
"John Baker" <jo********@comcast.net> wrote in message
news:cv********************************@4ax.com...
Hi:

I have read a number of threads on the issue of compressing (compacting)
Access data bases
programmatically, and have been left confused. We are using Access 2000,
and I need code
that will programmatically compress an open database. (called
"InvoiceManagement.be).

Can someone give me a piece of code that will do this, or a pointer to
one, please?

Thanks

John Baker

You should not be trying to compact a database which others might be using.

I don't believe there is one standard solution to this because it depends on
a number of factors:
Is the database split front/back end?
Is there user-level security?
When should this action happen - by user click or scheduled automatically?

Your code should
establish that no-one is using the database to be compacted ('original.mdb')
rename it to 'temp.mdb' (makes sure no-one is using it, or will be able to
during compact routine)
take a copy called 'copy1.mdb'
compact this to a new database 'copy2.mdb'
if all goes well, rename 'copy2.mdb' 'original.mdb'
delete 'copy1.mdb' and 'temp.mdb'
Mar 14 '06 #2
Anthony:

I am a bit of a neophyte with this aspect of access.

The db is single user right now, so no problem there. However, I am not certain of the
code to use to accomplish what I want.

I stumbled on this code in the Access Web site:

Public Sub CompactDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction

End Sub

I have installed it, and can run it from a button called directlt, but would like to
combine it with some other actions, and don't appear to be able to set up as "code" call
in a macro that will execute it.

The actual code does the job when i execute it through the debugger, but it wont execute
when I try and set it up using a macro. I would like to make it into an nice easy button
press to remove a lot of excess data (old historical data that is unnecessary) and
compress the files, but if the code wont execute in a macro this is hard to accomplish,
since Im not skilled in Basic code.

Best

John

"Anthony England" <ae******@oops.co.uk> wrote:
"John Baker" <jo********@comcast.net> wrote in message
news:cv********************************@4ax.com.. .
Hi:

I have read a number of threads on the issue of compressing (compacting)
Access data bases
programmatically, and have been left confused. We are using Access 2000,
and I need code
that will programmatically compress an open database. (called
"InvoiceManagement.be).

Can someone give me a piece of code that will do this, or a pointer to
one, please?

Thanks

John Baker

You should not be trying to compact a database which others might be using.

I don't believe there is one standard solution to this because it depends on
a number of factors:
Is the database split front/back end?
Is there user-level security?
When should this action happen - by user click or scheduled automatically?

Your code should
establish that no-one is using the database to be compacted ('original.mdb')
rename it to 'temp.mdb' (makes sure no-one is using it, or will be able to
during compact routine)
take a copy called 'copy1.mdb'
compact this to a new database 'copy2.mdb'
if all goes well, rename 'copy2.mdb' 'original.mdb'
delete 'copy1.mdb' and 'temp.mdb'


Mar 14 '06 #3

"John Baker" <jo********@comcast.net> wrote in message
news:u0********************************@4ax.com...
Anthony:

I am a bit of a neophyte with this aspect of access.

The db is single user right now, so no problem there. However, I am not
certain of the
code to use to accomplish what I want.

I stumbled on this code in the Access Web site:

Public Sub CompactDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction

End Sub

I have installed it, and can run it from a button called directlt, but
would like to
combine it with some other actions, and don't appear to be able to set up
as "code" call
in a macro that will execute it.

The actual code does the job when i execute it through the debugger, but
it wont execute
when I try and set it up using a macro. I would like to make it into an
nice easy button
press to remove a lot of excess data (old historical data that is
unnecessary) and
compress the files, but if the code wont execute in a macro this is hard
to accomplish,
since Im not skilled in Basic code.

Best

John

"Anthony England" <ae******@oops.co.uk> wrote:
"John Baker" <jo********@comcast.net> wrote in message
news:cv********************************@4ax.com. ..
Hi:

I have read a number of threads on the issue of compressing (compacting)
Access data bases
programmatically, and have been left confused. We are using Access 2000,
and I need code
that will programmatically compress an open database. (called
"InvoiceManagement.be).

Can someone give me a piece of code that will do this, or a pointer to
one, please?

Thanks

John Baker

You should not be trying to compact a database which others might be
using.

I don't believe there is one standard solution to this because it depends
on
a number of factors:
Is the database split front/back end?
Is there user-level security?
When should this action happen - by user click or scheduled automatically?

Your code should
establish that no-one is using the database to be compacted
('original.mdb')
rename it to 'temp.mdb' (makes sure no-one is using it, or will be able to
during compact routine)
take a copy called 'copy1.mdb'
compact this to a new database 'copy2.mdb'
if all goes well, rename 'copy2.mdb' 'original.mdb'
delete 'copy1.mdb' and 'temp.mdb'


You won't find much use of macros in this newsgroup as they only offer
limited functionality - most work is done with vba. But anyway, I take it
from your reply that the database is not split (so you have one mdb file
with tables and forms in it), you have no security implemented and there are
no multi-user issues.
In that case you can just modify the code you found so that it is a function
, rather than a sub:

Public Function CompactDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction

End Function
Then you can use this in a macro by having a step of RunCode and fill in the
function name:

=CompactDB()

Note that this needs to be the final step of any macro as Access needs to
re-start the database during this step and a macro cannot continue during
this.

Note that you could also just switch on the CompactOnClose option, so the
database is automatically compcted.



Mar 14 '06 #4
Anthony:

Thanks for your comments, I appreciate them. Unfortunately the DB and the programs are
split, so that there is a back end and a front end. I don't know if this impacts what you
advised, but I thought I should at least mention it,.

By the way, what is the "CompactOnClose" option, and how do I activate it?
Thanks again

John Baker

"Anthony England" <ae******@oops.co.uk> wrote:

"John Baker" <jo********@comcast.net> wrote in message
news:u0********************************@4ax.com.. .
Anthony:

I am a bit of a neophyte with this aspect of access.

The db is single user right now, so no problem there. However, I am not
certain of the
code to use to accomplish what I want.

I stumbled on this code in the Access Web site:

Public Sub CompactDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction

End Sub

I have installed it, and can run it from a button called directlt, but
would like to
combine it with some other actions, and don't appear to be able to set up
as "code" call
in a macro that will execute it.

The actual code does the job when i execute it through the debugger, but
it wont execute
when I try and set it up using a macro. I would like to make it into an
nice easy button
press to remove a lot of excess data (old historical data that is
unnecessary) and
compress the files, but if the code wont execute in a macro this is hard
to accomplish,
since Im not skilled in Basic code.

Best

John

"Anthony England" <ae******@oops.co.uk> wrote:
"John Baker" <jo********@comcast.net> wrote in message
news:cv********************************@4ax.com ...
Hi:

I have read a number of threads on the issue of compressing (compacting)
Access data bases
programmatically, and have been left confused. We are using Access 2000,
and I need code
that will programmatically compress an open database. (called
"InvoiceManagement.be).

Can someone give me a piece of code that will do this, or a pointer to
one, please?

Thanks

John Baker
You should not be trying to compact a database which others might be
using.

I don't believe there is one standard solution to this because it depends
on
a number of factors:
Is the database split front/back end?
Is there user-level security?
When should this action happen - by user click or scheduled automatically?

Your code should
establish that no-one is using the database to be compacted
('original.mdb')
rename it to 'temp.mdb' (makes sure no-one is using it, or will be able to
during compact routine)
take a copy called 'copy1.mdb'
compact this to a new database 'copy2.mdb'
if all goes well, rename 'copy2.mdb' 'original.mdb'
delete 'copy1.mdb' and 'temp.mdb'


You won't find much use of macros in this newsgroup as they only offer
limited functionality - most work is done with vba. But anyway, I take it
from your reply that the database is not split (so you have one mdb file
with tables and forms in it), you have no security implemented and there are
no multi-user issues.
In that case you can just modify the code you found so that it is a function
, rather than a sub:

Public Function CompactDB()

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction

End Function
Then you can use this in a macro by having a step of RunCode and fill in the
function name:

=CompactDB()

Note that this needs to be the final step of any macro as Access needs to
re-start the database during this step and a macro cannot continue during
this.

Note that you could also just switch on the CompactOnClose option, so the
database is automatically compcted.




Mar 15 '06 #5

"John Baker" <jo********@comcast.net> wrote in message
news:6g********************************@4ax.com...
Anthony:

Thanks for your comments, I appreciate them. Unfortunately the DB and the
programs are
split, so that there is a back end and a front end. I don't know if this
impacts what you
advised, but I thought I should at least mention it,.

By the way, what is the "CompactOnClose" option, and how do I activate it?
Thanks again

John Baker


Hi John
Yes it does make a difference - in fact it was one of the first questions I
asked. The difference it makes is that you could be compacting either the
front or the back end. Normally, it is the back end which needs compacting
as this is what holds the data and which has the additions and deletions
that cause the bloat (the space is not automatically re-claimed after
records are deleted)
So, what you need to do is compact the back end from the front end - this is
something the compact on close cannot do for you. This, by the way, is
under Tools>Options>General tab and simply compacts the database
automatically when you close it.
However, in your case, you should create a new module named "modCompact" and
cut and paste the following code into it. You need to alter one line where
you write in the name of any front-end linked table instead of:
"ReplaceThisWithYourTableName"
Make sure it compiles and then save the database. You can now have a macro
with a step of RunCode where you write in the name of the function
=CompactBackEnd()

I have tested this code, but I can't guarantee it, so test cautiously.
' *** Code Starts ***
Option Compare Database
Option Explicit

Private Const TABLE_NAME As String = "ReplaceThisWithYourTableName"
'
'

Public Function CompactBackEnd() As Boolean

On Error GoTo Err_Handler

Dim strBackEndPath As String
Dim strBackEndDir As String
Dim strBackEndFile As String
Dim strTempPath As String
Dim strCopyPath1 As String
Dim strCopyPath2 As String
Dim strStartSize As String
Dim strStopSize As String
Dim strWarning As String

strBackEndPath = BackEndPath(TABLE_NAME)

If Len(strBackEndPath) > 0 Then
strBackEndFile = Dir(strBackEndPath)
Else
MsgBox "Cannot locate datasource", vbCritical, _
"Compact and Repair Routine"
Exit Function
End If

If Len(strBackEndFile) > 0 Then
strBackEndDir = Left$(strBackEndPath, _
Len(strBackEndPath) - Len(strBackEndFile))
Else
MsgBox "Cannot locate datasource", vbCritical, _
"Compact and Repair Routine"
Exit Function
End If

strTempPath = strBackEndDir & "tmp" & strBackEndFile

strCopyPath1 = strBackEndDir & "tmpCopyDb1.mdb"

strCopyPath2 = strBackEndDir & "tmpCopyDb2.mdb"

strWarning = "A temporary file has been detected." & vbCrLf & _
"This may have come from a previous attempt " & _
"to compact and repair the database." & vbCrLf & _
"If you are sure this holds no useful data " & _
"then it may be deleted." & vbCrLf & "Otherwise rename " &
_
"or move the file to another location." & vbCrLf & vbCrLf &
_
"The current path is:" & vbCrLf

If Len(Dir(strTempPath)) > 0 Then
MsgBox strWarning & strTempPath, vbCritical, _
"Compact and Repair Routine"
Exit Function
End If

If Len(Dir(strCopyPath1)) > 0 Then
MsgBox strWarning & strCopyPath1, vbCritical, _
"Compact and Repair Routine"
Exit Function
End If

If Len(Dir(strCopyPath2)) > 0 Then
MsgBox strWarning & strCopyPath2, vbCritical, _
"Compact and Repair Routine"
Exit Function
End If

Name strBackEndPath As strTempPath

strStartSize = GetFileSize(strTempPath)

FileCopy strTempPath, strCopyPath1

DBEngine.CompactDatabase strCopyPath1, strCopyPath2

strStopSize = GetFileSize(strCopyPath2)

Name strCopyPath2 As strBackEndPath

Kill strCopyPath1

Kill strTempPath

MsgBox "Backup complete for:" & strBackEndPath & vbCrLf & _
"Compacted from: " & strStartSize & _
" to " & strStopSize, vbInformation, _
"Compact and Repair Routine"

CompactBackEnd = True

Exit_Handler:
Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function
Private Function BackEndPath(strTableName As String) As String

On Error GoTo Err_Handler

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim strPath As String

Set dbs = CurrentDb

Set tdf = dbs.TableDefs(strTableName)

If Len(tdf.Connect) > 0 Then
strPath = Mid$(tdf.Connect, 11)
End If

BackEndPath = strPath

Exit_Handler:

If Not tdf Is Nothing Then
Set tdf = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Exit Function

Err_Handler:
'No error message just return a zero-length string
Resume Exit_Handler

End Function

Private Function GetFileSize(strPath As String) As String

On Error GoTo Err_Handler

Dim intFile As Integer
Dim lngSize As Long
Dim sngSize As Single
Dim Digit As Byte
Dim strReturn As String

intFile = FreeFile

Open strPath For Binary Access Read As #intFile

lngSize = LOF(intFile)

Close #intFile

Select Case lngSize

Case Is > 1073741824
sngSize = lngSize / 1073741824
strReturn = "GB " & Format(sngSize, "###,###.000")

Case Is > 1048576
sngSize = lngSize / 1048576
strReturn = "MB " & Format(sngSize, "###,###.000")

Case Else
sngSize = lngSize / 1024
strReturn = "KB " & Format(sngSize, "###,###.000")

End Select

Digit = CByte(Right$(strReturn, 1))

If Digit > 4 Then
Digit = Digit + 1
End If

strReturn = Left$(strReturn, Len(strReturn) - 2) & CStr(Digit)

If Right$(strReturn, 3) = ".00" Then
strReturn = Left$(strReturn, Len(strReturn) - 3)
Else
If Right$(strReturn, 1) = "0" Then
strReturn = Left$(strReturn, Len(strReturn) - 1)
End If
End If

strReturn = Mid$(strReturn, 4) & " " & Left$(strReturn, 2)

GetFileSize = strReturn

Exit_Handler:
Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function
' *** Code Ends ***
Mar 15 '06 #6
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:
So, what you need to do is compact the back end from the front
end. . . .
Keep in mind that you won't be able to compact as long as any tables
in the back end are open by any users. This includes the user
initiating the compact from the front end -- if there is any bound
form open, it will prevent the back end from being compacted.
. . . - this is
something the compact on close cannot do for you.


I think compact on close is a useless and dangerous feature. Given
that it can potentially cause you to lose information/data, I don't
think it's good to have it happen without being requested by the
user.

Secondly, a well-designed front end should never need to be
compacted, and no well-designed application will ever be opening
anything other than the front end. Thus, it's a useless feature.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Mar 15 '06 #7

"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn**********************************@127.0.0. 1...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:
So, what you need to do is compact the back end from the front
end. . . .
Keep in mind that you won't be able to compact as long as any tables
in the back end are open by any users. This includes the user
initiating the compact from the front end -- if there is any bound
form open, it will prevent the back end from being compacted.


Indeed - so my routine temporarily renames the file which:
a) ensures that (if succesful) no-one else had been using it
b) stops people normally connecting to it while the code is running
. . . - this is
something the compact on close cannot do for you.


I think compact on close is a useless and dangerous feature. Given
that it can potentially cause you to lose information/data, I don't
think it's good to have it happen without being requested by the
user.


I agree.

Secondly, a well-designed front end should never need to be
compacted, and no well-designed application will ever be opening
anything other than the front end. Thus, it's a useless feature.
I pretty much agree, athough Access is frequently used by people who have an
all-in-one mdb file which is used exclusively by them on a single-user
machine. Nevertheless, unless you had reliable backup I would be cautious
of having it done automatically.
I never take any steps to try and compact front ends which I have
distributed and are being used. Some of these have been working for many
years without any need to compact. While I am working on them, however, I
compact regularly.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

Mar 15 '06 #8

"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn**********************************@127.0.0. 1...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:
So, what you need to do is compact the back end from the front
end. . . .
Keep in mind that you won't be able to compact as long as any tables
in the back end are open by any users. This includes the user
initiating the compact from the front end -- if there is any bound
form open, it will prevent the back end from being compacted.


Indeed - so my routine temporarily renames the file which:
a) ensures that (if succesful) no-one else had been using it
b) stops people normally connecting to it while the code is running
. . . - this is
something the compact on close cannot do for you.


I think compact on close is a useless and dangerous feature. Given
that it can potentially cause you to lose information/data, I don't
think it's good to have it happen without being requested by the
user.


I agree.

Secondly, a well-designed front end should never need to be
compacted, and no well-designed application will ever be opening
anything other than the front end. Thus, it's a useless feature.
I pretty much agree, athough Access is frequently used by people who have an
all-in-one mdb file which is used exclusively by them on a single-user
machine. Nevertheless, unless you had reliable backup I would be cautious
of having it done automatically.
I never take any steps to try and compact front ends which I have
distributed and are being used. Some of these have been working for many
years without any need to compact. While I am working on them, however, I
compact regularly.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

Mar 15 '06 #9
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com:

"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn**********************************@127.0.0. 1...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:
So, what you need to do is compact the back end from the front
end. . . .
Keep in mind that you won't be able to compact as long as any
tables in the back end are open by any users. This includes the
user initiating the compact from the front end -- if there is any
bound form open, it will prevent the back end from being
compacted.


Indeed - so my routine temporarily renames the file which:


Er, you can't rename a file that's open, so it's really no different
than a compact, which exclusively locks the MDB while it's working.
a) ensures that (if succesful) no-one else had been using it
b) stops people normally connecting to it while the code is
running


A regular compact does both of those things, and you couldn't rename
it in any circumstance where you also couldn't compact it.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Mar 15 '06 #10

"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn*********************************@127.0.0.1 ...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com:

"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn**********************************@127.0.0. 1...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:

So, what you need to do is compact the back end from the front
end. . . .

Keep in mind that you won't be able to compact as long as any
tables in the back end are open by any users. This includes the
user initiating the compact from the front end -- if there is any
bound form open, it will prevent the back end from being
compacted.


Indeed - so my routine temporarily renames the file which:


Er, you can't rename a file that's open, so it's really no different
than a compact, which exclusively locks the MDB while it's working.
a) ensures that (if succesful) no-one else had been using it
b) stops people normally connecting to it while the code is
running


A regular compact does both of those things, and you couldn't rename
it in any circumstance where you also couldn't compact it.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/


Do you really think I don't know this, or are you trying to wind me up?
The code was written in response to someone asking how to compact the back
end from with a function he could use in a macro. If the code is able to
re-name the file, I know that no-one had been in the file at the time and it
is my green light to proceed with the compact. The OP specifically says the
database is single-user, so there is no error handling to deal with the file
being open - it will simply stop if the file can't be re-named. However,
this could easily be modified to take some other action.
If you have a better solution, please feel free to let the OP know.
Mar 16 '06 #11
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:

"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn*********************************@127.0.0.1 ...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com:

"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in
message news:Xn**********************************@127.0.0. 1...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:

> So, what you need to do is compact the back end from the front
> end. . . .

Keep in mind that you won't be able to compact as long as any
tables in the back end are open by any users. This includes the
user initiating the compact from the front end -- if there is
any bound form open, it will prevent the back end from being
compacted.

Indeed - so my routine temporarily renames the file which:


Er, you can't rename a file that's open, so it's really no
different than a compact, which exclusively locks the MDB while
it's working.
a) ensures that (if succesful) no-one else had been using it
b) stops people normally connecting to it while the code is
running


A regular compact does both of those things, and you couldn't
rename it in any circumstance where you also couldn't compact it.


Do you really think I don't know this, or are you trying to wind
me up? The code was written in response to someone asking how to
compact the back end from with a function he could use in a macro.
If the code is able to re-name the file, I know that no-one had
been in the file at the time and it is my green light to proceed
with the compact. The OP specifically says the database is
single-user, so there is no error handling to deal with the file
being open - it will simply stop if the file can't be re-named.
However, this could easily be modified to take some other action.
If you have a better solution, please feel free to let the OP
know.


If my comments about renaming the file are irrelevant to the OP's
question, then my comments about compacting were irrelevant as well.
You didn't see fit to criticize those, so I'm not sure why you're
changing your tune now.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Mar 16 '06 #12

"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn**********************************@127.0.0. 1...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:

"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in message
news:Xn*********************************@127.0.0.1 ...
"Anthony England" <ae******@oops.co.uk> wrote in
news:dv**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com:
"David W. Fenton" <XX*******@dfenton.com.invalid> wrote in
message news:Xn**********************************@127.0.0. 1...
> "Anthony England" <ae******@oops.co.uk> wrote in
> news:dv**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com:
>
>> So, what you need to do is compact the back end from the front
>> end. . . .
>
> Keep in mind that you won't be able to compact as long as any
> tables in the back end are open by any users. This includes the
> user initiating the compact from the front end -- if there is
> any bound form open, it will prevent the back end from being
> compacted.

Indeed - so my routine temporarily renames the file which:

Er, you can't rename a file that's open, so it's really no
different than a compact, which exclusively locks the MDB while
it's working.

a) ensures that (if succesful) no-one else had been using it
b) stops people normally connecting to it while the code is
running

A regular compact does both of those things, and you couldn't
rename it in any circumstance where you also couldn't compact it.


Do you really think I don't know this, or are you trying to wind
me up? The code was written in response to someone asking how to
compact the back end from with a function he could use in a macro.
If the code is able to re-name the file, I know that no-one had
been in the file at the time and it is my green light to proceed
with the compact. The OP specifically says the database is
single-user, so there is no error handling to deal with the file
being open - it will simply stop if the file can't be re-named.
However, this could easily be modified to take some other action.
If you have a better solution, please feel free to let the OP
know.


If my comments about renaming the file are irrelevant to the OP's
question, then my comments about compacting were irrelevant as well.
You didn't see fit to criticize those, so I'm not sure why you're
changing your tune now.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/


Because I suddenly got irritated.
Because I suddenly wondered whether the OP would ever read the code
....let alone try it - and here I am debating whether an open file can be
re-named or not with someone who has no interest in using the code.
I sometimes wonder what I am doing here at all.
Mar 16 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nicola | last post by:
Hi Everyone, I am new to programming and would like to know how to open an access Report from within vb 6. I am trying to write a program to organise cross stitch threads. I have found out how...
17
by: chicha | last post by:
Hey people, I have to convert MS Access 2000 database into mysql database, the whole thing being part of this project I'm doing for one of my faculty classes. My professor somehow presumed I...
3
by: *no spam* | last post by:
I want to move my Access 2K database into MSDE. The Access Upsizing Wizard crashes (a known bug wi A2K), so I'm using the following suggested method: Access --> New --> Project (Existing...
63
by: Jerome | last post by:
Hi, I'm a bit confused ... when would I rather write an database application using MS Access and Visual Basic and when (and why) would I rather write it using Visual Studio .Net? Is it as easy...
13
by: Simon Bailey | last post by:
I am a newcomer to databases and am not sure which DBMS to use. I have a very simplified knowledge of databases overall. I would very much appreciate a (simplifed) message explaining the advantages...
11
by: Rosco | last post by:
Does anyone have a good URL or info whre Oracle and Access are compared to one another in performance, security, cost etc. Before you jump on me I know Oracle is a Cadillac compared to Access the...
64
by: John | last post by:
Hi What future does access have after the release of vs 2005/sql 2005? MS doesn't seem to have done anything major with access lately and presumably hoping that everyone migrates to vs/sql. ...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
21
by: nihad.nasim | last post by:
Hi there, I have a database in Access that I need on the web. The web page should connect to the database and write records for certain tables and view records for others. I want to know a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.