Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access Back using VBA

Status
Not open for further replies.

Mrogersy

Programmer
Jun 17, 2005
7
US
I am trying to automatically create a back up of a database on form load. I am not having any luck with the code I have found, I am only a intermediate programmer. Does anybody have any code to create a back up on form load? Here is the code I was trying to use:

Dim strRootPath
Dim strFileName As Database
Dim objScript


Dim strPrefix
Dim strMonth
Dim strDay
Dim strHour
Dim strMinute

Dim strSource
Dim strTarget
Dim strMsg

strRootPath = "G:\ACC_ATS\MikeCRogers\Cash Card Audit (930)\Archive"
strFileName = "BackUp.mdb"

strMonth = DatePart("m", Date)
If Len(strMonth) = 1 Then strMonth = "0" & strMonth

strDay = DatePart("d", Date)
If Len(strDay) = 1 Then strDay = "0" & strDay

strYear = Right(DatePart("yyyy", Date), 2)

strHour = DatePart("h", Now())
If Len(strHour) = 1 Then strHour = "0" & strHour

strMinute = DatePart("n", Now())
If Len(strMinute) = 1 Then strMinute = "0" & strMinute

strPrefix = strMonth & strDay & strYear & "-" & strHour & strMinute & "_"

strSource = strRootPath & strFileName
strTarget = strRootPath & "Archive" & strPrefix & strFileName

Set objScript = CreateObject("Scripting.FileSystemObject")

If Not objScript.FolderExists(strRootPath & "Archive\") Then
objScript.CreateFolder (strRootPath & "Archive\")
End If

'objScript.CopyFile strSource, strTarget


Set objScript = Nothing

strMsg = "The file:" & vbCrLf & Space(5) & strPrefix & strFileName & vbCrLf & vbCrLf & "Has been created in the Archive Folder."
MsgBox strMsg, , "Finished"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top