back up using vba

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to automatically back up an access file using visual basic?
 
"Accessidiot"

Yes, code it and then make part of the scheduled tasks so the back up can be
done at a certain time (like 2:00 am) when nobody is using your files or you
can create the VB file and run it everyday.
 
The question is sorry how do I code it?
Thanks

Ricoy-Chicago said:
"Accessidiot"

Yes, code it and then make part of the scheduled tasks so the back up can be
done at a certain time (like 2:00 am) when nobody is using your files or you
can create the VB file and run it everyday.
 
Are your file (s) in a network or stand alone? if you are in a network you
can back up your work using VB Script instead of VB. Here's the VB Script
coding I use to backup my files from the Server drive to my computer. The
script is run from my computer:

Option Explicit
On Error Resume Next

'****************************************************************************
'* *
'* Comments *
'* *
'****************************************************************************

'----------------------------------------------------------------------------
' Instantiate the script objects
'----------------------------------------------------------------------------
Dim objNet : Set objNet = CreateObject("WScript.Network")
Dim objFS : Set objFS = Wscript.CreateObject("Scripting.FileSystemObject")
Dim WSHShell : Set WSHShell = Wscript.CreateObject("Wscript.Shell")
Dim objFolder, BtnCode

objNet.MapNetworkDrive "DriveLetterInServer:",
"\\PathanametoFolder\FolderName"

'----------------------------------------------------------------------------
' Copy file
'----------------------------------------------------------------------------
btnCode = wshShell.Popup("Please wait...Copying files...", 3, "Copying...",
64)
objFS.Copyfile "DriveLetterInServer:\DirectoryName\Filename.mdb",
"C:\BackupDirectoryName\FileName.mdb"
'repeat previous line for each file
btnCode = wshShell.Popup("Your files has been copied. CLOSE this
window now...", 0, "ALL DONE!", 64)

'----------------------------------------------------------------------------
' Release objects from memory and terminate execution
'----------------------------------------------------------------------------
Set objNet = nothing
Set objFS = Nothing
Set WSHShell = nothing
Set objFolder = nothing
WScript.Quit

I am asuming you're familiar with VB or VB Scripts.

You can visit //groups.msn.com/windowsscript for additional help.
 
My files are on a stand alone, I was want ing to backup to a Memory stick E:
Thanks
 
I am assuming that you are a little bit familiar with VB.

here is the code, it assumes that the memory stick is already attached to
the computer, also you can delete the btncode= lines if you do not want the
message boxess to pop up.

Copy and paste the code into NOTEPAD. save the file with the extension .VBS
For example:
BACKUP.VBS, save the file as type: All Files Do not save it as a text file!
If you need help you can post an e-mail where i can send you an attachement.

good luck

Option Explicit
On Error Resume Next

'*
'*
'* This script backs up files to a memory stick
'*
'* Replace the text FolderName with the name of your folder
'* Replace the text AccessFileName with your file name make sure to type
'* the extension .mdb
'* repeat the objFS.copyfile line for each file to be copied
'*
'----------------------------------------------------------------------------
' Instantiate the script objects
'----------------------------------------------------------------------------
Dim objFS : Set objFS = Wscript.CreateObject("Scripting.FileSystemObject")
Dim WSHShell : Set WSHShell = Wscript.CreateObject("Wscript.Shell")
Dim objFolder, BtnCode

'----------------------------------------------------------------------------
' Copy file(s)
'----------------------------------------------------------------------------
btnCode = wshShell.Popup("Please wait...Updating your files...", 2,
"Copying...", 64)
objFS.Copyfile "C:\FolderName\AccessFileName.mdb",
"E:\FolderName\AccessFileName.mdb"
btnCode = wshShell.Popup("Please wait...Updating your files...", 2,
"Copying...", 64)
btnCode = wshShell.Popup("Your file(s) have been updated. Close this
window now...", 0, "ALL DONE!", 64)

'----------------------------------------------------------------------------
' Release objects from memory and terminate execution
'----------------------------------------------------------------------------
Set objFS = Nothing
Set WSHShell = nothing
Set objFolder = nothing
WScript.Quit
 
I want to do the same thing, although I want to first compress the file into
a Windows compressed folder and the location I want to send the compressed
backup file to is my FTP site. Is this possible and how would the coding
change?
 
Also...how do I initiate this script in Access. If I create a Command
Button, is this script in the "On Click" VB code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top