473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

automatic backup

I’m backing up my BE from within Access; although the filesize is relatively modest (15Mb) for this day and age it can take 3 or 4 minutes for the backup to be completed. There’s nothing I can do about that, it’s a network issue beyond my control. My problem is that Access is semi-suspended whilst the backup takes place; I say semi-suspended because if the user goes into another windows app e.g. explorer, word etc, and then back into access, the screen will go blank and it will appear as though access has hung. It hasn’t of course, it’s just waiting for the backup to be compoleted.

Hiding the windows file copy dialog has no effect on the problem, just means there’s nothing to view. Ditto putting up a little popup to say ‘backing up, please wait’ etc.

Ideally I’d like to trigger the backup and immediately return control to the user with the file copy taking place entirely outside of Access. I’ve tried triggering a batch file instead of an API call, but this too makes no difference, the problem remains. Alternatively I’d settle for ‘locking’ the user into access until the code has finished. Does anyone have a solution for either of these, or a better suggestion. Unfortunately I can’t take the easy and obvious route (network backup), that would require a degree of coordination well beyond this organisation!
Nov 12 '07 #1
2 2358
MMcCarthy
14,534 Expert Mod 8TB
What code exactly are you using for the backup. Can you post the code?
Nov 14 '07 #2
What code exactly are you using for the backup. Can you post the code?
Sorry for the timelag, holidays etc; as you can see this is quite a long chunk of code!
Thanks
Kevin


Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Function DailyBackup()
  4. On Error GoTo Proc_Err
  5.  
  6. Dim NumberLoggedIn
  7. Dim MyDay
  8. Dim MyMonth
  9. Dim MyYear
  10. Dim MyExpiredBackup
  11. Dim fs
  12. Dim strSaveFile As String
  13.  
  14. Application.Echo False
  15.  
  16. If EnableBackups = -1 Then
  17.     Set fs = CreateObject("Scripting.FileSystemObject")
  18.     strSaveFile = BackUpDirectory & Day(Date) & "-" & Month(Date) & "-" & Year(Date) & " Backup " & BE_FileName
  19.     If fs.FileExists(strSaveFile) = True Then
  20.         Set fs = Nothing
  21.         GoTo Proc_Exit
  22.     End If
  23.  
  24.     MyDay = Day(Date - 7)
  25.     MyMonth = Month(Date - 7)
  26.     MyYear = Year(Date - 7)
  27.     MyExpiredBackup = BackUpDirectory & MyYear & "-" & MyMonth & "-" & MyDay & " Backup " & BE_FileName
  28.  
  29.     NumberLoggedIn = DLookup("[MyCount]", "qryLoggedInCount", "[LoggedIn] = -1 ")
  30.  
  31.     If NumberLoggedIn = 1 Then
  32.         fMakeBackup
  33.         If fs.FileExists(MyExpiredBackup) = True Then
  34.             Kill MyExpiredBackup
  35.             Set fs = Nothing
  36.         End If
  37.     End If
  38. End If
  39.  
  40. Proc_Exit:
  41.     Application.Echo True
  42.     Exit Function
  43.  
  44. Proc_Err:
  45.     MsgBox "Oops, that must be error number " & Err.Number & ": " & Err.Description, vbInformation + vbOKOnly + vbDefaultButton1, "Case Management Database"
  46.     Resume Proc_Exit
  47.  
  48. End Function
  49.  
  50.  
  51. '********** Code Start *************
  52. ' This code was originally written by Dev Ashish.
  53. ' It is not to be altered or distributed,
  54. ' except as part of an application.
  55. ' You are free to use it in any application,
  56. ' provided the copyright notice is left unchanged.
  57. '
  58. ' Code Courtesy of
  59. ' Dev Ashish
  60. '
  61. Private Type SHFILEOPSTRUCT
  62.     hwnd As Long
  63.     wFunc As Long
  64.     pFrom As String
  65.     pTo As String
  66.     fFlags As Long
  67.     fAnyOperationsAborted As Boolean
  68.     hNameMappings As Long
  69.     lpszProgressTitle As String
  70. End Type
  71.  
  72. Private Const FO_MOVE As Long = &H1
  73. Private Const FO_COPY As Long = &H2
  74. Private Const FO_DELETE As Long = &H3
  75. Private Const FO_RENAME As Long = &H4
  76.  
  77. Private Const FOF_MULTIDESTFILES As Long = &H1
  78. Private Const FOF_CONFIRMMOUSE As Long = &H2
  79. Private Const FOF_SILENT As Long = &H4
  80. Private Const FOF_RENAMEONCOLLISION As Long = &H8
  81. Private Const FOF_NOCONFIRMATION As Long = &H10
  82. Private Const FOF_WANTMAPPINGHANDLE As Long = &H20
  83. Private Const FOF_CREATEPROGRESSDLG As Long = &H0
  84. Private Const FOF_ALLOWUNDO As Long = &H40
  85. Private Const FOF_FILESONLY As Long = &H80
  86. Private Const FOF_SIMPLEPROGRESS As Long = &H100
  87. Private Const FOF_NOCONFIRMMKDIR As Long = &H200
  88.  
  89. Private Declare Function apiSHFileOperation Lib "Shell32.dll" _
  90.             Alias "SHFileOperationA" _
  91.             (lpFileOp As SHFILEOPSTRUCT) _
  92.             As Long
  93.  
  94. Function fMakeBackup() As Boolean
  95. Dim strMsg As String
  96. Dim tshFileOp As SHFILEOPSTRUCT
  97. Dim lngRet As Long
  98. Dim strSaveFile As String
  99. Dim lngFlags As Long
  100.  
  101. Const cERR_USER_CANCEL = vbObjectError + 1
  102. Const cERR_DB_EXCLUSIVE = vbObjectError + 2
  103.     On Local Error GoTo fMakeBackup_Err
  104.  
  105.     If fDBExclusive = True Then Err.Raise cERR_DB_EXCLUSIVE
  106.  
  107.     'strMsg = "Are you sure that you want to make a copy of the database?"
  108.     'If MsgBox(strMsg, vbQuestion + vbYesNo, "Please confirm") = vbNo Then _
  109.             Err.Raise cERR_USER_CANCEL
  110.  
  111.     lngFlags = FOF_SIMPLEPROGRESS Or _
  112.                             FOF_FILESONLY Or _
  113.                             FOF_RENAMEONCOLLISION
  114.     'previously used fCurrentDBDir etc
  115.     'strSaveFile = fCurrentDBDir & Day(Date) & "-" & Month(Date) & "-" & Year(Date) & " Backup " & fCurrentDBFile
  116.     strSaveFile = BackUpDirectory & Day(Date) & "-" & Month(Date) & "-" & Year(Date) & " Backup " & BE_FileName
  117.  
  118.     With tshFileOp
  119.         .wFunc = FO_COPY
  120.         .hwnd = hWndAccessApp
  121.         '.pFrom = CurrentDb.Name & vbNullChar
  122.         .pFrom = BackUpDirectory & BE_FileName ' & vbNullChar
  123.         .pTo = strSaveFile & vbNullChar
  124.         .fFlags = lngFlags
  125.     End With
  126.     lngRet = apiSHFileOperation(tshFileOp)
  127.     fMakeBackup = (lngRet = 0)
  128.  
  129. fMakeBackup_End:
  130.     Exit Function
  131. fMakeBackup_Err:
  132.     fMakeBackup = False
  133.     Select Case Err.Number
  134.         Case cERR_USER_CANCEL:
  135.             'do nothing
  136.         Case cERR_DB_EXCLUSIVE:
  137.             MsgBox "The current database " & vbCrLf & CurrentDb.Name & vbCrLf & _
  138.                     vbCrLf & "is opened exclusively.  Please reopen in shared mode" & _
  139.                     " and try again.", vbCritical + vbOKOnly, "Database copy failed"
  140.         Case Else:
  141.             strMsg = "Error Information..." & vbCrLf & vbCrLf
  142.             strMsg = strMsg & "Function: fMakeBackup" & vbCrLf
  143.             strMsg = strMsg & "Description: " & Err.Description & vbCrLf
  144.             strMsg = strMsg & "Error #: " & Format$(Err.Number) & vbCrLf
  145.             MsgBox strMsg, vbInformation, "fMakeBackup"
  146.     End Select
  147.     Resume fMakeBackup_End
  148. End Function
  149.  
  150. Private Function fCurrentDBDir() As String
  151. 'code courtesy of
  152. 'Terry Kreft
  153. Dim strDBPath As String
  154. Dim strDBFile As String
  155.     strDBPath = CurrentDb.Name
  156.     strDBFile = Dir(strDBPath)
  157.     fCurrentDBDir = Left(strDBPath, InStr(strDBPath, strDBFile) - 1)
  158. End Function
  159.  
  160. Private Function fCurrentDBFile() As String
  161. 'code courtesy of
  162. 'Terry Kreft
  163. Dim strDBPath As String
  164. Dim strDBFile As String
  165.     strDBPath = CurrentDb.Name
  166.     strDBFile = Dir(strDBPath)
  167.     fCurrentDBFile = strDBFile
  168. End Function
  169.  
  170. Function fDBExclusive() As Long
  171. Dim DB As Database
  172. Dim hFile As Long
  173.     hFile = FreeFile
  174.     Set DB = CurrentDb
  175.     On Error Resume Next
  176.     Open DB.Name For Binary Access Read Write Shared As hFile
  177.     Select Case Err
  178.         Case 0
  179.             fDBExclusive = False
  180.         Case 70
  181.             fDBExclusive = True
  182.         Case Else
  183.             fDBExclusive = Err
  184.     End Select
  185.     Close hFile
  186.     On Error GoTo 0
  187. End Function
  188. '************* Code End ***************
Nov 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: bryja_klaudiusz[at]poczta[dot]fm | last post by:
Hi, How to automate database backup (MSDE server v8.0)? Is some free tool which can help on this or can I use some stored procedure? Plan: Complete - 1 per week Differential - 1 per day --...
3
by: apple | last post by:
UDB v8 fp 6a on AIX 5.1.0.0 Below is a manual incremental recover from compressed backup datasets. With external compress backup datasets, can it be coded to do an automatic incremental recover?...
6
by: Gert van der Kooij | last post by:
Hi, It's no problem to define the automatic maintenance using the wizard but I want to use commands to automate automation. I captured the SQL statements when activating the maintenance but that...
9
by: khan | last post by:
can any one help me how to create an automatic backup of ms access database. Actually I want it to be done either by just clicking on a button or automatally make a backup at 6pm every day. plz help
1
by: Michel Esber | last post by:
Hello, Linux RedHat AS4 running DB2 V8 FP11. I have followed the docs at http://tinyurl.com/qckrn and enabled automatic statistics collection. It has been 2 days since I updated my DB cfg and...
2
by: ray | last post by:
I have a client that doesn't want Access to automatically repair into a backup file if it crashes (and it crashes only on very rare occasions). My (sketchy) understanding is that this is a...
0
by: swarna_nama | last post by:
i need to configure the db2 database for automatic backup and need to maintain atleast 2 backup images of the database in db2 . I have updated the configuration parameters auto_maint and...
0
by: =?Utf-8?B?TmFzc2VyIEJ1bmR1a2E=?= | last post by:
Hello, Configuring incremental NT Backup in windows XP Professional From start menu go to RUN. ntbackup.exe Advance Mode Backup Wizard (Advanced Mode) Next and specify backup Items Locate...
3
by: Justin | last post by:
What is the difference between automatic and DMS Auto-resize tablespace?
3
by: saurabhsingh | last post by:
Hi I need to take automatic backup of my sqlserver2005 database per day. And I don't want to replace old backup,a new backup should be made per day. Thanks in advance
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.