473,414 Members | 1,740 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,414 software developers and data experts.

how to compact and repair a database from other database ?

222 100+
Hy to all

I'm using access 2003 (11.5614.5606)

I have a database called "form" that I imported all my forms on it and I linked tables of "forms " into another database called "tables" what I need is any method using VB to compact and repair "table" database from a form in "form" database


is that possible guys ????
Oct 28 '07 #1
2 2234
NeoPa
32,556 Expert Mod 16PB
I have a CommandButton (cmdCompact) on a form (frmCompact).
I'll copy in the code but beware, as it refers to other procedures I've had to chop and change it somewhat.
To follow shortly when I've done the fixing.
Oct 29 '07 #2
NeoPa
32,556 Expert Mod 16PB
Here's the code :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Const conJob As String = "Compact Databases"
  5. Private Const conStub As String = "Compact"
  6. Private Const conWarning As String = _
  7.                   "You are about to %S all Access Databases that this " & _
  8.                   "database links to." & vbCrLf & vbCrLf & _
  9.                   "If you are happy to continue press OK, " & _
  10.                   "otherwise press Cancel to abort."
  11.  
  12. Private Sub cmdCompact_Click()
  13.     Dim strWork As String, strDBs As String
  14.     Dim intPos As Integer, intLen As Integer
  15.     Dim tblThis As TableDef
  16.  
  17.     strWork = Replace(conWarning, "%S", conStub)
  18.     If MsgBox(Prompt:=strWork, _
  19.               Buttons:=vbQuestion Or vbOKCancel, _
  20.               Title:=conJob) <> vbOk Then Exit Sub
  21.  
  22.     Call DoCmd.SetWarnings(False)
  23.     strDBs = ""
  24.     For Each tblThis In CurrentDb.TableDefs
  25.         strWork = ConnectName(tblThis.Name)
  26.         If strWork > "" Then
  27.             strWork = """" & strWork & """" & vbCrLf
  28.             If InStr(1, strDBs, strWork) = 0 Then _
  29.                 strDBs = strDBs & strWork
  30.         End If
  31.     Next tblThis
  32.     intPos = 2
  33.     Do
  34.         intLen = InStr(intPos, strDBs, vbCrLf) - intPos - 1
  35.         If CompactDb(Mid(strDBs, intPos, intLen)) Then
  36.             intPos = intPos + intLen + 4
  37.         Else
  38.             strDBs = Left(strDBs, intPos - 2) & _
  39.                      Mid(strDBs, intPos + intLen + 3)
  40.         End If
  41.     Loop Until intPos > Len(strDBs)
  42.     strWork = "The following databases were compacted:%L%D"
  43.     strWork = Replace(strWork, "%L", vbCrLf)
  44.     strWork = Replace(strWork, "%D", strDBs)
  45.     Call MsgBox(Prompt:=strWork, Buttons:=vbInformation, Title:=conJob)
  46.     Call DoCmd.SetWarnings(True)
  47. End Sub
Oct 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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...
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 exists", whenever I try to look for this table I...
4
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...
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 re-installed Office 2003 using Detect and Repair but...
2
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...
9
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...
2
by: RZ15 | last post by:
Hi, I was working on a query this morning and everything was working fine. Some time in the last half hour, I used the Compact & Repair Database feature. After that, when I went to open the query...
3
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...
4
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
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 automated way? How do you make sure that the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.