|
In this article I am going to show you how you can backup and restore a database in Microsoft Visual Basic 6.0.
Backup:
First
of all create a new project and add a Text box and a button as shown in the
image.Now double click the backup button to view its code handler. In the code
window declare a FileSystemObject in the general
section of the code window.Then write the following code in the click
event of backup button.
Dim fileSys As New FileSystemObject
Private Sub Command2_Click()
If Text1 <> "" Then
fileSys.CopyFile App.Path & "\opd.mdb", App.Path & "\Backup\" & Text1.Text & ".BKP", True 'want to have a filename as celeste..haha.. you can change it into diff. names ok!hahah
MsgBox "Yes! Backup Successful! ", vbInformation, "Backup"
Unload Me
Else
MsgBox "Invalid filename", vbCritical, "Backup"
End If
End Sub
Private Sub Form_Load()
With fileSys
If .FolderExists(App.Path & "\Backup") = False Then .CreateFolder (App.Path & "\Backup")
End With
Restore:-
First of all create a new form and add a Text box, Fie listbox and a button as shown in the image.Now double click the Restore button to view its code handler. In the code window declare a FileSystemObject in the general section of the code window.Then write the following code in the click event of Restore button.
Dim fileSys As New FileSystemObject
Private Sub Form_Load()
With fileSys
If .FolderExists(App.Path & "\Backup") = False Then .CreateFolder (App.Path & "\Backup")
End With
With File1
.Path = App.Path & "\Backup\"
.Pattern = "*.BKP"
End With
End Sub
Private Sub Command1_Click()
If Text1 <> "" Then
fileSys.CopyFile App.Path & "\opd.mdb", App.Path & "\Backup\Before" & Text1, True
fileSys.CopyFile App.Path & "\Backup\" & Text1, App.Path & "\opd.mdb", True
MsgBox "Restore Successful!", vbInformation, "Restore Backup"
Unload Me
Else
MsgBox "invalid Filename", vbCritical
End If
End Sub
1 comments:
SIR, how to muliple DB backup and restore
Post a Comment