title image


Smiley Re: Automatische Sicherungskopie einer Datenbank beim schließen
Hallo Lilly,Machs besser nicht mit DOS. Die Datenbank wird auf Dauer inkl. Sicherungskopie korrupt und kaputt und das ist ja nicht Sinn und Zweck. Über eine offene DB mit der Eisenbahn drüber fahren ist nicht schön.Die beste Sicherungskopie ist und bleibt das Backup.Es gibt noch Code von Dev Ashish, in der die Datei über API - shared geöffnet wird und außerdem weiß Dev Ashish was er tut.'********** Code Start *************'This code was originally written by Dev Ashish.'It is not to be altered or distributed,'except as part of an application.'You are free to use it in any application,'provided the copyright notice is left unchanged.''Code Courtesy of'Dev Ashish''geringfügigst von mir abgeändertPrivate Type SHFILEOPSTRUCT hWnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAnyOperationsAborted As Boolean hNameMappings As Long lpszProgressTitle As StringEnd TypePrivate Const FO_MOVE As Long = &H1Private Const FO_COPY As Long = &H2Private Const FO_DELETE As Long = &H3Private Const FO_RENAME As Long = &H4Private Const FOF_MULTIDESTFILES As Long = &H1Private Const FOF_CONFIRMMOUSE As Long = &H2Private Const FOF_SILENT As Long = &H4Private Const FOF_RENAMEONCOLLISION As Long = &H8Private Const FOF_NOCONFIRMATION As Long = &H10Private Const FOF_WANTMAPPINGHANDLE As Long = &H20Private Const FOF_CREATEPROGRESSDLG As Long = &H0Private Const FOF_ALLOWUNDO As Long = &H40Private Const FOF_FILESONLY As Long = &H80Private Const FOF_SIMPLEPROGRESS As Long = &H100Private Const FOF_NOCONFIRMMKDIR As Long = &H200Private Declare Function apiSHFileOperation Lib "Shell32.dll" _ Alias "SHFileOperationA" _ (lpFileOp As SHFILEOPSTRUCT) _ As LongFunction fMakeBackup(Sicherungspfad As String) As BooleanDim strMsg As StringDim tshFileOp As SHFILEOPSTRUCTDim lngRet As LongDim strSaveFile As StringDim lngFlags As LongConst cERR_USER_CANCEL = vbObjectError + 1Const cERR_DB_EXCLUSIVE = vbObjectError + 2 On Local Error GoTo fMakeBackup_Err If fDBExclusive = True Then Err.Raise cERR_DB_EXCLUSIVE strMsg = "Sin Sie sich sicher, daß Sie eine Datenbankkopie machen wollen?" If Msgbox(strMsg, vbQuestion + vbYesNo, "Please confirm") = vbNo Then _ Err.Raise cERR_USER_CANCEL lngFlags = FOF_SIMPLEPROGRESS Or _ FOF_FILESONLY Or _ FOF_RENAMEONCOLLISION strSaveFile = CurrentDb.Name With tshFileOp .wFunc = FO_COPY .hWnd = hWndAccessApp .pFrom = CurrentDb.Name & vbNullChar .pTo = Sicherungspfad .fFlags = lngFlags End With lngRet = apiSHFileOperation(tshFileOp) fMakeBackup = (lngRet = 0) fMakeBackup_End: Exit FunctionfMakeBackup_Err: fMakeBackup = False Select Case Err.Number Case cERR_USER_CANCEL: 'do nothing Case cERR_DB_EXCLUSIVE: Msgbox "Die Datenbank " & vbCrLf & CurrentDb.Name & vbCrLf & _ vbCrLf & "ist exclusiv geöffnet. Bitte im Modus gemeinsame Nutzung öffnen!" & _ " and try again.", vbCritical + vbOKOnly, "Database copy failed" Case Else: strMsg = "Error Information..." & vbCrLf & vbCrLf strMsg = strMsg & "Function: fMakeBackup" & vbCrLf strMsg = strMsg & "Description: " & Err.Description & vbCrLf strMsg = strMsg & "Error #: " & Format$(Err.Number) & vbCrLf Msgbox strMsg, vbInformation, "fMakeBackup" End Select Resume fMakeBackup_EndEnd FunctionFunction fDBExclusive() As IntegerDim db As DatabaseDim hFile As Integer hFile = FreeFile Set db = CurrentDb On Error Resume Next Open db.Name For Binary Access Read Write Shared As hFile Select Case Err Case 0 fDBExclusive = False Case 70 fDBExclusive = True Case Else fDBExclusive = Err End Select Close hFile On Error GoTo 0End Function'************* Code End ***************'Aufruf mit _Call fMakeBackup("A:\Name_der_SicherungsDB.mdb")GrußWalter

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: