VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Compact and Repair *.MDB database.

by Vinu Menon (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Mon 6th October 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Compact and Repair *.MDB database.

Rate Compact and Repair *.MDB database.



'Task               :   To Compact and Repair MDB file
'Date of submission :   10-06-2003
'Developed by       :   Vinu Menon & Pavan Kumar
'Organization       :   Bay Talkitec (P) Ltd. -Hyderabad

'Steps to follow
'
'1  :   Referece the following DLL's
'       Microsoft DAO 3.6 Object Lib
'2  :   Add the following components
'       Microsoft Common Dialog Control
'       Microsoft Windows Common Control 6.0
'
'3  :   Place the Following Controls on the form
'       Textbox         : Name = txtFilePath
'       CommonDialog    : Name = CommonDialog
'       ProgressBar     : Name = ProgressBar
'       CommandButton   : Name = cmdCompactRepair : Name = cmdExit
'       Timer           : Name = Timer1 Set the initial Enable value = FALSE
'
'
'
'FOR COMMENTS and SUGGESTIONS, Plz. mail me on [email protected]
'
'
'E N J O Y

Private Sub cmdBrowse_Click()
CommonDialog.DialogTitle = " Compact and Repair database" 'Set the Common Dialog Title
CommonDialog.Filter = "Microsoft Access Database (*.MDB) | *.MDB" ' Display only MDB files
CommonDialog.ShowOpen 'Show Open Dialog
CommonDialog.CancelError = True 'Cancel all errors
CommonDialog.DefaultExt = "*.MDB" ' Set the default extension
txtFilePath = CommonDialog.FileName ' Put the selected filename in the textbox
End Sub

Private Sub cmdCompactRepair_Click()
Dim dbE As New DAO.DBEngine ' Declare a new DBEngine variable
Dim x$ ' To capture the DIR return string


x = Dir(App.Path & "\repairedDB.mdb") 'see if the TempPath already exists

If x <> "" Then Kill App.Path & "\repairedDB.mdb" 'Check if the Temp file already exists

Timer1.Enabled = True 'Enable the Timer

dbE.CompactDatabase txtFilePath, App.Path & "\RepairedDB" ' Compact and repair the DB

Kill txtFilePath 'Kill the original DB

'Rename the Repaired DB with the Original DB Name
Name App.Path & "\repairedDB.mdb" As txtFilePath

End Sub

Private Sub cmdExit_Click()
End 'Close the application
End Sub

Private Sub Form_Load()
ProgressBar.Min = 0 ' Set the Min value
ProgressBar.Max = 100 ' Set the Max value
If txtFilePath = "" Then cmdCompactRepair.Enabled = False
End Sub

Private Sub Timer1_Timer()
'Check the progressbar value counter
If ProgressBar.Value < 100 Then
    ProgressBar.Value = ProgressBar.Value + 10
Else
    MsgBox " DataBase successfully Compacted", vbInformation + vbSystemModal, "Compact & Repair Database Demo"
    ProgressBar.Value = 0 'Reset the min value
    Timer1.Enabled = False 'Disable the Timer
End If
End Sub

Private Sub txtFilePath_Change()
If txtFilePath = "" Then
    cmdCompactRepair.Enabled = False
Else
    cmdCompactRepair.Enabled = True
End If
End Sub

Private Sub txtFilePath_LostFocus()
If txtFilePath = "" Then
    cmdCompactRepair.Enabled = False
Else
    cmdCompactRepair.Enabled = True
End If

End Sub


Download this snippet    Add to My Saved Code

Compact and Repair *.MDB database. Comments

No comments have been posted about Compact and Repair *.MDB database.. Why not be the first to post a comment about Compact and Repair *.MDB database..

Post your comment

Subject:
Message:
0/1000 characters