please help... BACK UP DB

  • Thread starter Thread starter marco_pb via AccessMonster.com
  • Start date Start date
M

marco_pb via AccessMonster.com

hi all.... thank you for all your helps at all my posts....
I have another question here... HOW can I create duplicate (or back up file)
of the database after I click a button in a form..
This is possible, isn't it?
thank you in advance for your help.
 
If you're saying you want to backup the MDB file while you have it open, no,
it's not possible.

Okay, that's not 100% accurate. There are techniques that will let you copy
the open file. The point is, it's not a good idea: you have no idea what
state the data is in the database, so the copied file may be internally
inconsistent.

You might consider looking at MichKa's free TSI SOON (Shut One, Open New)
database add-in at http://www.trigeminal.com/utility.asp?ItemID=8#8.
 
Not any file you've got open exclusively no. Take a look
here at Copy a Database by Dev Ashish using the API -

http://www.mvps.org/access/api/api0026.htm

Alternatively you could set up a script to copy the file(s)
at a time when no one is using the database.

If you want to backup your design objects then take a look
at Terry Kreft and Dev Ashish's Backup to text file Module
here
http://www.mvps.org/access/modules/mdl0045.htm

Good luck

--
Nick Coe (UK)
http://www.alphacos.co.uk/ AccHelp is now Free
http://www.mrcomputersltd.com/ Repairs Upgrades

In marco_pb via AccessMonster.com typed:
 
Thank you all for the help.. thank you...
I have copy the code here:

'********** 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

Private 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 String
End Type

Private Const FO_MOVE As Long = &H1
Private Const FO_COPY As Long = &H2
Private Const FO_DELETE As Long = &H3
Private Const FO_RENAME As Long = &H4

Private Const FOF_MULTIDESTFILES As Long = &H1
Private Const FOF_CONFIRMMOUSE As Long = &H2
Private Const FOF_SILENT As Long = &H4
Private Const FOF_RENAMEONCOLLISION As Long = &H8
Private Const FOF_NOCONFIRMATION As Long = &H10
Private Const FOF_WANTMAPPINGHANDLE As Long = &H20
Private Const FOF_CREATEPROGRESSDLG As Long = &H0
Private Const FOF_ALLOWUNDO As Long = &H40
Private Const FOF_FILESONLY As Long = &H80
Private Const FOF_SIMPLEPROGRESS As Long = &H100
Private Const FOF_NOCONFIRMMKDIR As Long = &H200

Private Declare Function apiSHFileOperation Lib "Shell32.dll" _
Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) _
As Long

Function fMakeBackup() As Boolean
Dim strMsg As String
Dim tshFileOp As SHFILEOPSTRUCT
Dim lngRet As Long
Dim strSaveFile As String
Dim lngFlags As Long
Const cERR_USER_CANCEL = vbObjectError + 1
Const cERR_DB_EXCLUSIVE = vbObjectError + 2
On Local Error GoTo fMakeBackup_Err

If fDBExclusive = True Then Err.Raise cERR_DB_EXCLUSIVE

strMsg = "Are you sure that you want to make a copy of the database?"
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 = strSaveFile & vbNullChar
.fFlags = lngFlags
End With
lngRet = apiSHFileOperation(tshFileOp)
fMakeBackup = (lngRet = 0)

fMakeBackup_End:
Exit Function
fMakeBackup_Err:
fMakeBackup = False
Select Case Err.Number
Case cERR_USER_CANCEL:
'do nothing
Case cERR_DB_EXCLUSIVE:
MsgBox "The current database " & vbCrLf & CurrentDb.Name & vbCrLf
& _
vbCrLf & "is opened exclusively. Please reopen in shared
mode" & _
" 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_End
End Function

Private Function fCurrentDBDir() As String
'code courtesy of
'Terry Kreft
Dim strDBPath As String
Dim strDBFile As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
fCurrentDBDir = Left(strDBPath, InStr(strDBPath, strDBFile) - 1)
End Function

Function fDBExclusive() As Integer
Dim db As Database
Dim 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 0
End Function

I still got an error message but the copy is successfull. the error message
is: microsoft access can not find Object 0

i dont know how it can happens,,

thank you in advance for the links and the helps..
 
You'll need to put in some breaks and start debugging to see
where in the code the error is actually generated. That
will help you diagnose _exactly_ what is going on.

Until you narrow it down to see where the error is being
generated it's just guessing. And I would guess the file is
open when you're trying to copy it, but without debugging
info I could be completely wrong.

Do look into Doug's pointer to MichKa's site, you really
should close the file before copying it. I agree with Doug
completely about the danger of copying an open file.

Good luck

--
Nick Coe (UK)
http://www.alphacos.co.uk/ AccHelp is now Free
http://www.mrcomputersltd.com/ Repairs Upgrades

In marco_pb via AccessMonster.com typed:
 
Back
Top