Automatic Copy Database

gstylianou

Registered User.
Local time
Tomorrow, 00:23
Joined
Dec 16, 2013
Messages
359
Hi all,

There is a way using code to copy the back_end database? Please note that, i wanted to do that from Front_end Interface.

Thanks
 
Hi. I think so. Have a look here. Hope it helps...

Hi TheDBGuy and thanks but,

I modified the code as follow but i have problem because there is a password in my backend and i'm getting the error msg.

Option Compare Database
Option Explicit
Public Sub BackUpAndCompactBE()
'Courtesy of Brent Spaulding (datAdrenaline), MVP
'Source: http://accessmvp.com/theDBguy

On Error GoTo errHandler

Dim oFSO As Object
Dim strDestination As String
Dim strSource As String

'Get the source of your back end
strSource = Split(Split(CurrentDb.TableDefs("tblSettings").Connect, _
"Database=")(1), ";")(0)

'Determine your destination HERE I WANT A STANTART DESTINATION PATH AS :M:\Backup
strDestination = CurrentProject.Path & "\DATASET_MD216.0.0.1 (" _
& Format(Now, "yyyymmddhhnnss") & ").accde"

'Flush the cache of the current database
DBEngine.Idle

'Create a file scripting object that will backup the db
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.CopyFile strSource, strDestination
Set oFSO = Nothing

'Compact the new file, ...
Name strDestination As strDestination & ".cpk"
DBEngine.CompactDatabase strDestination & ".cpk", strDestination
Kill strDestination & ".cpk"

'Notify users
MsgBox "Backup file '" & strDestination & "' has been created.", _
vbInformation, "Backup Completed!"

errExit:
Exit Sub

errHandler:
MsgBox err.Number & ": " & err.Description
Resume errExit

End Sub
 

Attachments

  • Capture.JPG
    Capture.JPG
    16.3 KB · Views: 81
Another solution that i found and works perfect but i cannot run it within vba module is a Script file for backup. Anyone can help me in order to run the Script file within access form (command)?

attached is the Script
 

Attachments

Hi. Is that a typo? I see a space between the two n's in .Connect. Give me a sec and I'll try to test the code on a password-protected BE. If you debug the error, which line gets highlighted?
 
Hi. Is that a typo? I see a space between the two n's in .Connect. Give me a sec and I'll try to test the code on a password-protected BE. If you debug the error, which line gets highlighted?
Hi. This worked for me. Just replace "test" with your actual password.
Code:
    DBEngine.CompactDatabase strDestination & ".cpk", strDestination, , , ";pwd=test"
 
can you just not copy it like this

Code:
filecopy databasename as copyname
 
Oops, from what you posted it appears that user actually used the DBGuy's routine.
I never realised. Sorry the DBGuy :o
Hi. No worries. It's all good.
 
Hi. This worked for me. Just replace "test" with your actual password.
Code:
    DBEngine.CompactDatabase strDestination & ".cpk", strDestination, , , ";pwd=test"

Yeap, working.
Tell me something, how can i run external Script file using code into my form?
 
Hi. This worked for me. Just replace "test" with your actual password.
Code:
    DBEngine.CompactDatabase strDestination & ".cpk", strDestination, , , ";pwd=test"
Upon further testing, it appears this method will apply the given password to the backup BE as well, even if the original BE was not password protected. I may have to update the website with this note later on. It may or may not be a good side effect, but definitely worth letting everyone know. Cheers!
 
Yeap, working.
Tell me something, how can i run external Script file using code into my form?
There are several ways to run a script file from VBA. For example, you can use Shell or ShellExecute.
 
There are several ways to run a script file from VBA. For example, you can use Shell or ShellExecute.

TheDBGuy can you please give an example on how using command button to call the Script (Vbs) file please? And sorry for my last post....
 
TheDBGuy can you please give an example on how using command button to call the Script (Vbs) file please? And sorry for my last post....
Hi. I can't test this right now but try something like:
Code:
Shell "c:\foldername\scriptname.vbs"
 

Users who are viewing this thread

Back
Top Bottom