473,657 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automate Compact and Repair

Hi all,
I have a Access 2002 FE/BE scenario where the BE is stored on a network
drive. Due to the amount of importing/deleting, the database bloats quite a
lot. UP until now, I have been booting the users out of the database and
manually compacting it. What I am trying to do is automate the process so I
don't have to worry about it. My VB skills are few and far between so this
is proving somewhat of a challenge. Because I am trying to compact the
backend from the frontend, no users can be logged in. I think I have solved
this problem by getting the FE to close if the current user isn't the last
person that logged in.

With only one person logged in, all the forms are closed which I thought
would close a connection to the backend allowing the BE to be compacted.
When I run the code, all work well up until the compact where I get an error
stating that I have the database opened exclusively. Am I going about this
the wrong way or is there a way to make sure the connection is closed before
the compact?

Here is the code I have come up with.

Private Sub compactandreope n_click()
Dim rstUser As New ADODB.Recordset 'Last User
Dim rstForm As New ADODB.Recordset 'Form list
Dim UserStr As String
rstUser.Open "qry_LastLogin" , CurrentProject. Connection, adOpenStatic,
adLockReadOnly
rstForm.Open "qry_FrmLis t", CurrentProject. Connection, adOpenStatic,
adLockReadOnly
UserStr = rstUser!userid
If Forms!frm_user_ login!txt_user_ id = UserStr Then 'current user matches
last user logged in
Do Until rstForm.EOF 'Close All forms

If SysCmd(acSysCmd GetObjectState, acForm, "" & rstForm!name) <> 0 Then
DoCmd.Close acForm, "" & rstForm!name
Debug.Print rstForm!name
End If
rstForm.MoveNex t
Loop
rstForm.Close
Set rstForm = Nothing

'With all forms closed, compact backend
DBEngine.Compac tDatabase "K:\Systems\New BE.mde",
"K:\Systems\bac kup\NewBE.mde" 'This is where the code fails

DoCmd.OpenForm "frm_User_login ", acNormal, , , acFormEdit
Else
MsgBox "The database just closed"
'DoCmd.Quit 'Close the database
End If
End Sub

TIA Mark
Nov 13 '05 #1
1 4949
Hi All,
After a little playing around, I have managed a workaround. I found that the
connection does close once the forms are closed but not quick enough. I have
created an unbound form which is opened up once all other forms are closed.
On the timer event of this form which is set to 1 second, I have placed the
compact command. This gives enough time to close the connection and the
process completes as required.

If anyone has got any other suggestions on how to pause the code until the
connection is closed, it would be greatly appreciated.

Regards,

Mark
"Mark" <ma**********@n tlworld.com> wrote in message
news:4f******** ******@newsfe4-gui.ntli.net...
Hi all,
I have a Access 2002 FE/BE scenario where the BE is stored on a network
drive. Due to the amount of importing/deleting, the database bloats quite a
lot. UP until now, I have been booting the users out of the database and
manually compacting it. What I am trying to do is automate the process so I
don't have to worry about it. My VB skills are few and far between so this
is proving somewhat of a challenge. Because I am trying to compact the
backend from the frontend, no users can be logged in. I think I have solved
this problem by getting the FE to close if the current user isn't the last
person that logged in.

With only one person logged in, all the forms are closed which I thought
would close a connection to the backend allowing the BE to be compacted.
When I run the code, all work well up until the compact where I get an error
stating that I have the database opened exclusively. Am I going about this
the wrong way or is there a way to make sure the connection is closed before
the compact?

Here is the code I have come up with.

Private Sub compactandreope n_click()
Dim rstUser As New ADODB.Recordset 'Last User
Dim rstForm As New ADODB.Recordset 'Form list
Dim UserStr As String
rstUser.Open "qry_LastLogin" , CurrentProject. Connection, adOpenStatic,
adLockReadOnly
rstForm.Open "qry_FrmLis t", CurrentProject. Connection, adOpenStatic,
adLockReadOnly
UserStr = rstUser!userid
If Forms!frm_user_ login!txt_user_ id = UserStr Then 'current user matches
last user logged in
Do Until rstForm.EOF 'Close All forms

If SysCmd(acSysCmd GetObjectState, acForm, "" & rstForm!name) <> 0 Then
DoCmd.Close acForm, "" & rstForm!name
Debug.Print rstForm!name
End If
rstForm.MoveNex t
Loop
rstForm.Close
Set rstForm = Nothing

'With all forms closed, compact backend
DBEngine.Compac tDatabase "K:\Systems\New BE.mde",
"K:\Systems\bac kup\NewBE.mde" 'This is where the code fails

DoCmd.OpenForm "frm_User_login ", acNormal, , , acFormEdit
Else
MsgBox "The database just closed"
'DoCmd.Quit 'Close the database
End If
End Sub

TIA Mark

Nov 13 '05 #2

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

Similar topics

6
5569
by: KEVIN97810 | last post by:
Hello to all, Assume my mdb name is Cust.MDB. I want to compact & repair the same Cust.MDB when the user exit the program. Is there a way you can do it in code behind the EXIT button. I am dumping data from SQL to temp table and also delete from these tables in Cust.MDB. This would cause the MDB to get big. So I just want some code to compact and repair as user Exit from the access database. thanks a bunch.
3
5566
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 exists", whenever I try to look for this table I cannot find it anywhere... Any clues... Already went into the help file and nothing... Also try to copy my database and the same message comes up
4
2078
by: Wayne | last post by:
Does "Compact On Close" do a "Compact and Repair" or just a compact. Is a compact necessary (or at least a good idea) on a regular basis, say weekly, for a database that has several hundred records per week added to it? TIA.
4
2998
by: Andy Davis | last post by:
Is it possible to create a button with code to carry out the a weekly compact and repair of database and backup? My users know how to do this from the menu but would really like some kind process where they are reminded to do it and then just click the button to do so. Any tips on the best way forward would be much appreciated. Thanks in advance Dawn Davis
2
2779
by: Ron | last post by:
Hi All, Using WinXP pro/Access 2000. I have a database that's been used for about 5 months. Transferred lots of data from a dos based program, then the users have been using it for that 5 months. About 180000 records in one of the main files (maybe 25000 new since the dos conversion). Been having some speed issues crop up along the way (much faster to do same reports when I first transferred the data than now, with the new 25000...
9
3986
by: Ron | last post by:
New discovery. If I take a perfectly good database, and "compact/repair" on it with Access 2000 (seems to be at multiple sites--I've tried it with my system here, at another office on an entirely different network), it damages the file somehow. The user's machine that did the compact/repair can see the file fine. But any networked user can't get in. I can double click on a good database file from any user (over the network) and it...
0
1426
by: | last post by:
In an Access 2000 database in Access 2003 (Dutch) I have the following code: Option Compare Database Option Explicit Public Sub CompactDB() CommandBars("Menu Bar"). _ Controls("Tools"). _ Controls("Database utilities"). _ Controls("Compact and repair database..."). _
3
2201
by: Bizmark | last post by:
Access2003, Windows XP Pro OEM user OS, Windows Sever 2000 server OS. Not-so-recently I inherited 3 Access DB's from another company merging with our own. Our own system works off of SQL server, but mainting these databases is critical to keeping the business running. 1 database in particular has been causing problems. Along the course we have had a few problems with random records corrupting (new and old) and Values within fields...
4
3168
by: zufie | last post by:
When I Repair/Compact my Access databse. I get icons/copies of a database named db1.mdb, db2.mdb, db3.mdb, etc... How else may I repair this database? Thanks!, Zuf
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.