472,352 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

How to compact & Repair Back-end from Front-end

Hi folks,

Somewhere, I recently saw an article header titled:

"How to compact and Repair a back-end Access db from the front-end
using VBA" or words to that effect.

Now that I need it, I cannot find it. Does anyone know were to find
such an article?

Thanks
Nov 13 '05 #1
5 17486
Lauren Wilson wrote:
Hi folks,

Somewhere, I recently saw an article header titled:

"How to compact and Repair a back-end Access db from the front-end
using VBA" or words to that effect.

Now that I need it, I cannot find it. Does anyone know were to find
such an article?

Thanks


dbEngine.CompactDatabase "PathToSource" "PathToDestination"

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2
Lauren,

Are you still looking for a calendar report? Leave your email and I will
send you a screenshot of what I
have.

Access Resource

"Lauren Wilson" <no****@private.com> wrote in message
news:0l********************************@4ax.com...
Hi folks,

Somewhere, I recently saw an article header titled:

"How to compact and Repair a back-end Access db from the front-end
using VBA" or words to that effect.

Now that I need it, I cannot find it. Does anyone know were to find
such an article?

Thanks

Nov 13 '05 #3

Yes.

Send it to my partners: su*****@lmc.bz

Thanks
On Tue, 24 May 2005 13:11:22 GMT, "Access Resource"
<ac************@discussions.microsoft.com> wrote:
Lauren,

Are you still looking for a calendar report? Leave your email and I will
send you a screenshot of what I
have.

Access Resource

"Lauren Wilson" <no****@private.com> wrote in message
news:0l********************************@4ax.com.. .
Hi folks,

Somewhere, I recently saw an article header titled:

"How to compact and Repair a back-end Access db from the front-end
using VBA" or words to that effect.

Now that I need it, I cannot find it. Does anyone know were to find
such an article?

Thanks


Nov 13 '05 #4
Bri
Lauren Wilson wrote:
Hi folks,

Somewhere, I recently saw an article header titled:

"How to compact and Repair a back-end Access db from the front-end
using VBA" or words to that effect.

Now that I need it, I cannot find it. Does anyone know were to find
such an article?

Thanks


Lauren,

Rick has already mentioned the key piece needed but there are a few
things that you need to know about to make this work.

If the Backend is being accessed then the CompactDatabase method will
fail as it cannot get Exclusive use of it. Your code will need to trap
this error. Also, if your frontend maintains any attachments to the
backend (ie first form open opens a recordset on the backend to force
the backend ldb file to remain for the session - a known trick to
speedup FE-BE setups) you will need to have your code close them before
the compact (and I suppose reopen them after). In some situations, you
may need to 'unlink' the tables from the BE (test without first as it is
much easier to code). The newly compacted backend then needs to replace
the old backend. I usually leave it around as a backup (renamed). Below
my sig is a function I use as a starting place. I pass to it the name of
a table in the BE so it can get the name of the BE from its connection
string.

--
Bri

My code, watch for wrap.

Function Compactdb(TableName As String) As Boolean
On Error GoTo Err_CompactDB

'If Tables are always connected then use commented code
'Dim Connections() As String
Dim i, j As Integer
Dim tbl As TableDef
Dim stFileName

DoCmd.Hourglass True

stFileName = db.TableDefs(TableName).Connect
stFileName = Mid(stFileName, InStr(stFileName, "=") + 1)

'If Tables are always connected then use commented code
'i = db.TableDefs.Count
'ReDim Connections(i)
'j = 0
'For Each tbl In db.TableDefs
' Connections(j) = tbl.Connect
' If Left(tbl.Name, 4) <> "Msys" Then
' tbl.Connect = ""
' tbl.RefreshLink
' End If
' j = j + 1
'Next

DBEngine.CompactDatabase stFileName, stFileName & "TMP"
If Dir(stFileName & ".BCK") <> "" Then _
Kill stFileName & ".BCK"
Name stFileName As stFileName & ".BCK"
Name stFileName & "TMP" As stFileName
If Dir(stFileName & "TMP") <> "" Then _
Kill stFileName & "TMP"

Compactdb = True

'If Tables are always connected then use commented code
'j = 0
'For Each tbl In db.TableDefs
' If Left(tbl.Name, 4) <> "Msys" Then
' tbl.Connect = Connections(j)
' tbl.RefreshLink
' End If
' j = j + 1
'Next

Exit_Compactdb:
DoCmd.Hourglass False
Exit Function

Err_CompactDB:
DoCmd.Hourglass False
Compactdb = False
If Err.Number = 3356 Then
MsgBox "The database is currently being used by another User. " & _
"You can only Compact the Database if you are the only person " & _
"using it." & vbCr & _
vbCr & "Please try again later.", vbExclamation, & _
"Database in Use by Another User"
Else
MsgBox Err.Description
End If
Resume Exit_Compactdb

End Function

Nov 13 '05 #5

Thanks a lot Bri!
On Tue, 24 May 2005 17:33:11 GMT, Bri <no*@here.com> wrote:
Lauren Wilson wrote:
Hi folks,

Somewhere, I recently saw an article header titled:

"How to compact and Repair a back-end Access db from the front-end
using VBA" or words to that effect.

Now that I need it, I cannot find it. Does anyone know were to find
such an article?

Thanks


Lauren,

Rick has already mentioned the key piece needed but there are a few
things that you need to know about to make this work.

If the Backend is being accessed then the CompactDatabase method will
fail as it cannot get Exclusive use of it. Your code will need to trap
this error. Also, if your frontend maintains any attachments to the
backend (ie first form open opens a recordset on the backend to force
the backend ldb file to remain for the session - a known trick to
speedup FE-BE setups) you will need to have your code close them before
the compact (and I suppose reopen them after). In some situations, you
may need to 'unlink' the tables from the BE (test without first as it is
much easier to code). The newly compacted backend then needs to replace
the old backend. I usually leave it around as a backup (renamed). Below
my sig is a function I use as a starting place. I pass to it the name of
a table in the BE so it can get the name of the BE from its connection
string.


Nov 13 '05 #6

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

Similar topics

3
by: pwh777 | last post by:
I have three databases. DB1 has a button on a form. When I click that button, I want to import all the objects from DB2 to DB3 (just as you would...
3
by: Paolo | last post by:
Hi, I am trying to compact and repair my database, however every time I try it comes up a message saying: Table: "TempMSysAccessObject already...
6
by: GaryDave | last post by:
My school registration database has not been quite right after a recent compact and repair (done while I was away). Though most of the many forms...
2
by: ApexData | last post by:
Hello I have finally completed an application and am preparing to install it on a network of 10 users. The application will be split FE/BE. The...
2
by: Mark G. King | last post by:
I have Access 2003 SP2. When I open any database annd choose Tools / Database Utilities the menu item Compact And Repair is missing. I have...
3
by: G Gerard | last post by:
Hello The more I use an application ( an mdb) created using MSAccess I notice that the Byte size of the application keeps on increasing....
1
by: ncsthbell | last post by:
I have an Access 2000 database (running on Windows XP) that is used as a model and each user grabs a copy of this and puts onto their own drive. I...
4
by: Bob Alston | last post by:
For those of you that have replicated databases, how often to you compact and repair them? Also what mathod do you use if you do this on an...
9
by: Timmy! | last post by:
A2003 on Win XP Pro. A number of very stable apps I have are lately sometimes crashes when I do a compact & repair, especially when I hold the...
4
by: shalskedar | last post by:
The Compact & Repair option is not working on 1 of the computers .The Operating system used is Windows XP. In the Database,when the Compact &...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.