title: VBA code for creating Access Backup
body: <p>I just want to Create Backup file of access, so users from fronted can press button and a backup is created.</p>
  
  <p>I am trying this code, This makes the copy of database, but also copies my VBA Code. I just want to copy Tables. No forms, No reports.</p>
  
  <p>Is it possible to ZIP it from VBA??</p>
  
  <pre><code>Function fMakeBackup()
  
  Dim Source As String
  Dim Target As String
  Dim retval As Integer
  
  
  Source = CurrentDb.Name
  
  Target = "C:\Users\Documents\FileName"
  Target = Target &amp; Format(Date, "dd-mm") &amp; "   "
  Target = Target &amp; Format(Time, "hh-mm") &amp; ".accdb"
  
  ' create the backup
  retval = 0
  Dim objFSO As Object
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  retval = objFSO.CopyFile(Source, Target, True)
  Set objFSO = Nothing
  
  End Function
  </code></pre>
  
  <p><strong>Update 1</strong>
  Using solution given by @Sergey</p>
  
  <p>I modified code as below</p>
  
  <p>Function fMakeBackup()</p>
  
  <pre><code>Dim Target As String
  Target = "C:\Users\adarsh.madrecha\Downloads\Delete "
  Target = Target &amp; Format(Date, "dd-mm") &amp; " "
  Target = Target &amp; Format(Time, "hh-mm") &amp; ".accdb"
  
  ' create the Blank file for copying
  Access.DBEngine.CreateDatabase Target, DB_LANG_GENERAL
  
  Dim tdf As TableDef    
  For Each tdf In CurrentDb.TableDefs
     DoCmd.CopyObject Target, , acTable, tdf.Name
  Next
  
  End Function
  </code></pre>
  
  <p>When I execute this, a popup is shown </p>
  
  <p><a href="https://i.stack.imgur.com/w69zE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w69zE.png" alt="Access Security Box"></a></p>
  
  <p>If I click on either on the options, the code gives error. </p>
  
  <pre><code>Runtime error 3024 
  Copy object action was canceled 
  </code></pre>