Back up and zip code from ghudson (1 Viewer)

Oldsoftboss

AWF VIP
Local time
Tomorrow, 05:09
Joined
Oct 28, 2001
Messages
2,499
One thing I did add was to alter the line FindBackUpFile() Function in the basBackUp Module from:

CDInitDir = "C:\"

to:

CDInitDir = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))

This allows the Select File Dialog box to open at the folder where the open database is located. :)

Dave
 

madhouse

Registered User.
Local time
Today, 20:09
Joined
Jul 3, 2002
Messages
65
I apologise now for opening up old wounds, but I just tried ghudson's original code for backing up and zipping an open database and can't get it to work. I first of all change the paths to my E: Drive, and when that didn't work I then copied my database to C:\Database as in the example, but still no luck. I've stepped trough the code and all of the paths/filenames are correct, and a copy of the database is created in the 'backup' folder but the zip file isn't created. I've even tried adding in the SLEEP to pause the code but still nothing. I did search of all my hard drives to see if the zip file was elsewhere but nothing was found. Any ideas??
 

madhouse

Registered User.
Local time
Today, 20:09
Joined
Jul 3, 2002
Messages
65
I know this isn't mentioned anywhere within the thread, but do you need certain version of Winzip? I'm running 8.1 but looking on the winzip website it appears as though the latest version (9.0) has a free add-on to run DOS commands for zipping/unzipping files.
 

madhouse

Registered User.
Local time
Today, 20:09
Joined
Jul 3, 2002
Messages
65
ok, I've found the problem. It's because I'm using an evaluation version of winzip, and the call to winzip.exe with vbhide meant that the winzip "Evaluation Version" screen prompt wasn't being displayed to enable me to click the 'Use Evaluation Version' button. So I've got round this by changing vbHide to vbNormalFocus, but besides getting the full version of Winzip is there a way round this without the need for clicking the 'Use Evaluation Version' button each time?
 

checoturco

Registered User.
Local time
Today, 12:09
Joined
Oct 17, 2005
Messages
76
hi all,

i use this code but a get the error "No files were found for this action that match your criteria - nothing to do" this happens in this block of code.

If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile)

if i make de debug.print of sBackupPath & sBackupFile it gives me the the right path and file.


tks in advance
checoturco
 

Mirage Guaridan

New member
Local time
Today, 12:09
Joined
Jan 2, 2018
Messages
3
HI
This what I did with you'r code
when I use WINRAR
any comment please
to upgrade the code
You can see my attacchment ( copy.mdb )
Code:
Private Sub Command0_Click()
BackupAndZipit
End Sub

Private Sub Command1_Click()
MoveFiles
End Sub

Public Function BackupAndZipit()

'This function will allow you to copy a db that is open,
'rename the copied db and zip it up to anther folder.

'You must set a reference to the 'Microsoft Scripting Runtime' for the CopyFile piece to work!

'Thanks to Ricky Hicks for the .CopyFile code
DoCmd.SetWarnings True

Dim fso As FileSystemObject

Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String

sSourcePath = "Z:\ORG\data\"
sSourceFile = "data.mdb"
sBackupPath = "F:\"
sBackupFile = "BackupDB_.mdb"

Set fso = New FileSystemObject
fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
Set fso = Nothing

Dim sWinZip As String
Dim sZipFile As String
Dim sZipFileName As String
Dim sFileToZip As String

sWinZip = "C:\Program Files\WinRAR\winrar.exe" 'Location of the WinZip program
sZipFileName = Left(sBackupFile, InStr(1, sBackupFile, ".", vbTextCompare) - 1) & ".rar"
'sZipFileName = "BackupDB_.RAR"
sZipFile = sBackupPath & sZipFileName
sFileToZip = sBackupPath & sBackupFile
               'winrar a -afzip F:\BackupDB_.rar F:\BackupDB_.mdb
Call Shell(sWinZip & " a -afzip " & sZipFile & " " & sFileToZip, vbHide)
End Function


Public Function MoveFiles()
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you like to delete temp file ?"    ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2    ' Define buttons.
Title = "Delete your Temp File"    ' Define title.
Help = "DEMO.HLP"    ' Define Help file.
Ctxt = 1000    ' Define topic
        ' context.
        ' Display message.

Dim sSourcePath2 As String
Dim sSourceFile2 As String
Dim sBackupPath2 As String
Dim sBackupFile2 As String
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String
Dim I As Double

sSourcePath = "Z:\ORG\data\"
sSourceFile = "data.mdb"
sBackupPath = "F:\"
sBackupFile = "BackupDB_.mdb"
sSourcePath2 = "F:\"
sSourceFile2 = "BackupDB_.rar"
sBackupPath2 = "E:\"
sBackupFile2 = "BackupDB_" & Format(Date, "mmddyyyy") & "_" & Format(Time, "hhmmss") & ".rar"

Set fso = New FileSystemObject
fso.CopyFile sSourcePath2 & sSourceFile2, sBackupPath2 & sBackupFile2, True
Set fso = Nothing

I = 1
Beep
Response = MsgBox(Msg, Style, Title, Help, Ctxt)

If Response = vbYes Then
    If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile)
    If Dir(sSourcePath2 & sSourceFile2) <> "" Then Kill (sSourcePath2 & sSourceFile2)
End If



End Function
 

Attachments

  • Copy.mdb
    148 KB · Views: 81

Mirage Guaridan

New member
Local time
Today, 12:09
Joined
Jan 2, 2018
Messages
3
Sorry I haven't got back earlier. I had already doubled the copy code, also added the parse bit, as well as including a replace bit to replace any spaces with an underscore.
The attachment has A2000 as well as A97 for ghudson :p

If improvements can be made, please feel free.

If it looks OK I will post it in the Code Sample forum.

Dave

This is nice ...
 

Users who are viewing this thread

Top Bottom