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

Backup my database

I want to use the code below to back my access database application but its not running pls help me


Expand|Select|Wrap|Line Numbers
  1. Dim DBTempSource As Database
  2.  Dim DBTempDestination As Database
  3.  
  4.  Dim RecTempSource As Recordset
  5.  Dim RecTempDestination As Recordset
  6.  
  7.  Sub MBackup()
  8.  
  9.  Set FSO = CreateObject("Scripting.FileSystemObject")
  10.  On Error GoTo Errors
  11.  If OptBackup Then
  12.      TxtRemarks = "Backup Started at " & Time
  13.      TxtRemarks = TxtRemarks & vbCrLf & "Closing Connection ...!"
  14.      GCnnGeneral.Close
  15.      TxtRemarks = TxtRemarks & vbCrLf & "Checking Destination ...!"
  16.      If GFileExists(TxtDestination) Then
  17.          Kill TxtDestination
  18.      End If
  19.  
  20.      TxtRemarks = TxtRemarks & vbCrLf & "Compacting Source ..."
  21.      DBEngine.CompactDatabase TxtSource, TxtDestination, , , ";pwd=Debasis"
  22.      TxtRemarks = TxtRemarks & vbCrLf & "Destination Created ...!"
  23.      TxtRemarks = TxtRemarks & vbCrLf & "Connecting Database ...!"
  24.      With GCnnGeneral
  25.         .Provider = "Microsoft.Jet.OLEDB.4.0"
  26.         .Properties("Jet OLEDB:Database Password") = "Debasis"
  27.         .Mode = adModeReadWrite
  28.         .Open App.Path & "\" & Trim(GFileName) & ".MDB"
  29.      End With
  30.      'GFileName = Trim(LstDatabase.Text)
  31.      TxtRemarks = TxtRemarks & vbCrLf & "Backup Created at " & Time
  32.      MsgBox "Backup Created."
  33.      TxtSource = GEmptyStr
  34.      TxtDestination = GEmptyStr
  35.  ElseIf OptRestore Then
  36.      'GCnnAccts.Close
  37.      TxtRemarks = "Restoring Data Started at " & Time
  38.      GCnnGeneral.Close
  39.      TxtRemarks = TxtRemarks & vbCrLf & "Connection Closed ...!"
  40.      Kill TxtDestination
  41.      TxtRemarks = TxtRemarks & vbCrLf & "Destination Checked ...!"
  42.      Call FSO.CopyFile(TxtSource, TxtDestination, True)
  43.      TxtRemarks = TxtRemarks & vbCrLf & "Data Restored ...!"
  44.      With GCnnGeneral
  45.         .Provider = "Microsoft.Jet.OLEDB.4.0"
  46.         .Properties("Jet OLEDB:Database Password") = "Debasis"
  47.         .Mode = adModeReadWrite
  48.         .Open App.Path & "\" & Trim(GFileName) & ".MDB"
  49.      End With
  50.      TxtRemarks = TxtRemarks & vbCrLf & "Connection Complete ...!"
  51.      TxtRemarks = TxtRemarks & vbCrLf & "Data Restored at " & Time
  52.      MsgBox "Data Restored."
  53.  End If
  54.  
  55.  Exit Sub
  56.  Errors:
  57.      MsgBox "[ErrNo.: " & Err.Number & "] " & Err.Description
  58.  End Sub
  59.  
  60.  Private Sub CmdBackup_Click()
  61.  If Trim(TxtSource) = GEmptyStr Then
  62.      MsgBox "Source Filename Empty."
  63.      Exit Sub
  64.  End If
  65.  
  66.  If Trim(TxtDestination) = GEmptyStr Then
  67.      MsgBox "Destination Filename Empty."
  68.      Exit Sub
  69.  End If
  70.  
  71.  If OptBackup Then
  72.      If Not GFileExists(TxtSource) Then
  73.          MsgBox "Source File Does Not Exist! Please Contact Program Vendor."
  74.          Exit Sub
  75.      End If
  76.      If GFileExists(TxtDestination) Then
  77.          If MsgBox("Destination File Already Exists! Do you Want to Replace the File?", vbYesNo + vbQuestion) = vbNo Then
  78.              Exit Sub
  79.          End If
  80.      End If
  81.  ElseIf OptRestore Then
  82.      If Not GFileExists(TxtSource) Then
  83.          MsgBox "Source File Does Not Exist! Check Filename and Path."
  84.          Exit Sub
  85.      End If
  86.  End If
  87.  Call MBackup
  88.  End Sub
  89.  
  90.  Private Sub CmdDestinationSearch_Click()
  91.  If OptBackup Then
  92.      CDOpen.DefaultExt = "Bak"
  93.      CDOpen.FileName = "Temp.Bak"
  94.      CDOpen.ShowSave
  95.      TxtDestination = CDOpen.FileName
  96.  Else
  97.      TxtDestination = Replace(App.Path & "\" & Trim(GFileName) & ".MDB", "\\", "\")  'GFileName
  98.  End If
  99.  End Sub
  100.  
  101.  Private Sub CmdExit_Click()
  102.  Unload Me
  103.  End Sub
  104.  
  105.  Private Sub CmdSourceSearch_Click()
  106.  If OptBackup Then
  107.      TxtSource = Replace(App.Path & "\" & Trim(GFileName) & ".MDB", "\\", "\")    'GFileName
  108.  Else
  109.      CDOpen.DefaultExt = "Bak"
  110.      CDOpen.FileName = "Temp.Bak"
  111.      CDOpen.ShowOpen
  112.      TxtSource = CDOpen.FileName
  113.  End If
  114.  End Sub
  115.  
  116.  Private Sub Form_Resize()
  117.  Me.Left = (FrmBackground.Width - Me.Width) / 2
  118.  Me.Top = (FrmBackground.Height - Me.Height) / 2
  119.  End Sub
  120.  
  121.  Private Sub OptAll_Click()
  122.  FraPart.Visible = False
  123.  End Sub
  124.  
  125.  Private Sub OptBackup_Click()
  126.  CmdBackup.Caption = OptBackup.Caption & " &File"
  127.  TxtRemarks = GEmptyStr
  128.  End Sub
  129.  
  130.  Private Sub OptPart_Click()
  131.  FraPart.Visible = True
  132.  DtpFrom = Format(DateAdd("d", 7, GTransactDate), "dd/MMM/yyyy")
  133.  DtpTo = Format(GTransactDate, "dd/MMM/yyyy")
  134.  End Sub
  135.  
  136.  Private Sub OptRestore_Click()
  137.  CmdBackup.Caption = OptRestore.Caption & " &File"
  138.  TxtRemarks = GEmptyStr
  139.  End Sub
Jul 18 '11 #1
0 1156

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

Similar topics

3
by: Colin Finck | last post by:
Hello! I need to backup a MySQL database (MySQL 4.0). But it is on a shared-hosting web server and so I don't have direct server access. I also have no phpMyAdmin installed. How can I backup the...
3
by: Stanley Sinclair | last post by:
For years I have been hoping for a native db2 solution which compresses data on BACKUP DATABASE. (Using Windows.) I have heard that it will happen, but has anyone enough chutzpa to say if it will...
3
by: GB | last post by:
Are all database configuration parameters included in the database backup or not ? If I restore the database from the backup are these restored also ? What is the best way to backup and restore...
1
by: MeganF via AccessMonster.com | last post by:
Does it make sense to create an option to create a backup database. The folks I'm working with aren't set up really well in their office for automation. I'm helping by automating their invoice...
4
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...
4
by: fstenoughsnoopy | last post by:
I have a database on a server, not split into FE/BE and it has the user level security set up. I do have one problem. I need to back up the database. According to Microsoft and other books and...
3
by: ineedahelp | last post by:
Does anyone have an efficient way to MOVE tables to a backup database using code? Thanks in advance for any help!!
1
by: bwmiller16 | last post by:
Folks - DB21085I Instance "db2inst1" uses "32" bits and DB2 code release "SQL08022" with level identifier "03030106". Informational tokens are "DB2 v8.1.2.88", "s050422", "MI00117", and...
2
japuentem
by: japuentem | last post by:
I want to backup a database with the SQL Query Analizer with the following instruction: BACKUP DATABASE my_database TO DISK 'C:\backups\my_database.bak' WITH FORMAT GO and send me this error...
2
by: billalquist | last post by:
Here is what I am trying to do....I am using Access 2007. I created a form (frmEmailBudget) with a button (btnCreateBudgetBackup). This button needs to generate a backup of the active database...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.