Hi everyone, let me first start by saying I am horrible with programming and could really use anyones help. I have a database and I want to send it to some clients. The database contains a control panel that has a lot of buttons that link to different forms. I would like to have a control button that I press then it automatically zips the file and then sends it. Ghudson wrote a code that I am trying to work with but me being so bad with programming, I am having trouble.
1. I'm not sure where to put the code so that I can call it.
2. I'm not sure what I need to change in order for the code to operate correctly.
I currently changed the code and when I tried to compile it and it says "User-defined type not defined" and it highlights 'fso as FileSystemObject'. The parts I changed are sourcepath to where the file I am zipping is located, sourcefile to the name of the file I am zipping, sbackuppath to where to store the backup, for sbackupfile I did not know what to do so I left it alone, sWinzip was the same location as mine, and zipfilename, zipfile, filetozip I left alone.
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
Dim fso As FileSystemObject
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String
sSourcePath = "S:\CRNA\nawemugufs10vb\NAVSEA1$\CRNA\PED\PE30\QA42_QA43\QA43ML"
sSourceFile = "IPMSA-FY05.mdb"
sBackupPath = "S:\CRNA\nawemugufs10vb\NAVSEA1$\CRNA\PED\PE30\QA42_QA43\QA43ML\Backups"
sBackupFile = "BackupDB_" & Format(Date, "mmddyyyy") & "_" & Format(Time, "hhmmss") & ".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\WinZip\WinZip32.exe" 'Location of the WinZip program
sZipFileName = Left(sBackupFile, InStr(1, sBackupFile, ".", vbTextCompare) - 1) & ".zip"
sZipFile = sBackupPath & sZipFileName
sFileToZip = sBackupPath & sBackupFile
Call Shell(sWinZip & " -a " & sZipFile & " " & sFileToZip, vbHide)
Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & sBackupPath & Chr(13) & Chr(13) & "The backup file name is " & Chr(13) & Chr(13) & sZipFileName, vbInformation, "Backup Completed"
If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile)
End Function
Here is a link to the original code:
http://www.access-programmers.co.uk/forums/showthread.php?t=52238&highlight=backup
Any help would be greatly appreciated and if you could be as in depth as possible, because once again I am a little slow with programming.
Thank you
1. I'm not sure where to put the code so that I can call it.
2. I'm not sure what I need to change in order for the code to operate correctly.
I currently changed the code and when I tried to compile it and it says "User-defined type not defined" and it highlights 'fso as FileSystemObject'. The parts I changed are sourcepath to where the file I am zipping is located, sourcefile to the name of the file I am zipping, sbackuppath to where to store the backup, for sbackupfile I did not know what to do so I left it alone, sWinzip was the same location as mine, and zipfilename, zipfile, filetozip I left alone.
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
Dim fso As FileSystemObject
Dim sSourcePath As String
Dim sSourceFile As String
Dim sBackupPath As String
Dim sBackupFile As String
sSourcePath = "S:\CRNA\nawemugufs10vb\NAVSEA1$\CRNA\PED\PE30\QA42_QA43\QA43ML"
sSourceFile = "IPMSA-FY05.mdb"
sBackupPath = "S:\CRNA\nawemugufs10vb\NAVSEA1$\CRNA\PED\PE30\QA42_QA43\QA43ML\Backups"
sBackupFile = "BackupDB_" & Format(Date, "mmddyyyy") & "_" & Format(Time, "hhmmss") & ".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\WinZip\WinZip32.exe" 'Location of the WinZip program
sZipFileName = Left(sBackupFile, InStr(1, sBackupFile, ".", vbTextCompare) - 1) & ".zip"
sZipFile = sBackupPath & sZipFileName
sFileToZip = sBackupPath & sBackupFile
Call Shell(sWinZip & " -a " & sZipFile & " " & sFileToZip, vbHide)
Beep
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & sBackupPath & Chr(13) & Chr(13) & "The backup file name is " & Chr(13) & Chr(13) & sZipFileName, vbInformation, "Backup Completed"
If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile)
End Function
Here is a link to the original code:
http://www.access-programmers.co.uk/forums/showthread.php?t=52238&highlight=backup
Any help would be greatly appreciated and if you could be as in depth as possible, because once again I am a little slow with programming.
Thank you