Sunday 21 January 2018

Backup and Restore database in VB 6


Backup-and-Restore-database-in-VB6


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  

VB6

1 comments:

prabakaran on 28 February 2024 at 07:31 said...

SIR, how to muliple DB backup and restore

Post a Comment

 

© 2018 Mastering Web Development: HTML, Bootstrap, PHP, ASP.NET & VB.NET Essentials - Designed by Mukund | Privacy Policy | Sitemap

About Me | Contact Me | Write For Us