Path direction

  • Thread starter Afrosheen via AccessMonster.com
  • Start date
A

Afrosheen via AccessMonster.com

I'm using this routine to back up my database. The first part works as is.
What I want to do is to make the copy to A:\ drive.

1) strcopyfile = CurrentProject.Path & "\Copy of " & CurrentProject.Name


2) strcopyfile = CurrentProject. "A:\Copy of " & CurrentProject.Name

I keep on getting errors. Is there a way where I can save/backup a copy to A:\
drive?

Thanks for reading my post. It's been a great help.

This is the entire API that I'm using.

Option Compare Database
Option Explicit

'********** 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
10 On Local Error GoTo fMakeBackup_Err

20 If fDBExclusive = True Then Err.Raise cERR_DB_EXCLUSIVE

30 strMsg = "Are you sure that you want to make a copy of the database?
"
40 If MsgBox(strMsg, vbQuestion + vbYesNo, "Please confirm") = vbNo
Then _
Err.Raise cERR_USER_CANCEL

50 lngFlags = FOF_SIMPLEPROGRESS Or _
FOF_FILESONLY Or _
FOF_RENAMEONCOLLISION

60 strSaveFile = CurrentDb.Name
70 With tshFileOp
80 .wFunc = FO_COPY
90 .hWnd = hWndAccessApp
100 .pFrom = CurrentDb.Name & vbNullChar
110 .pTo = strSaveFile & vbNullChar
120 .fFlags = lngFlags
130 End With
140 lngRet = apiSHFileOperation(tshFileOp)
150 fMakeBackup = (lngRet = 0)

fMakeBackup_End:
160 Exit Function
fMakeBackup_Err:
170 fMakeBackup = False
180 Select Case Err.Number
Case cERR_USER_CANCEL:
'do nothing
190 Case cERR_DB_EXCLUSIVE:
200 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"
210 Case Else:
220 strMsg = "Error Information..." & vbCrLf & vbCrLf
230 strMsg = strMsg & "Function: fMakeBackup" & vbCrLf
240 strMsg = strMsg & "Description: " & Err.Description &
vbCrLf
250 strMsg = strMsg & "Error #: " & Format$(Err.Number) &
vbCrLf
260 MsgBox strMsg, vbInformation, "fMakeBackup"
270 End Select
280 Resume fMakeBackup_End
End Function

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

Function fDBExclusive() As Integer
Dim db As Database
Dim hFile As Integer
10 hFile = FreeFile
20 Set db = CurrentDb
30 On Error Resume Next
40 Open db.Name For Binary Access Read Write Shared As hFile
50 Select Case Err
Case 0
60 fDBExclusive = False
70 Case 70
80 fDBExclusive = True
90 Case Else
100 fDBExclusive = Err
110 End Select
120 Close hFile
130 On Error GoTo 0
End Function
'************* Code End ***************
 
A

Afrosheen via AccessMonster.com

Hi Douglas and thanks for your reply. It appears that it is trying to access
drive A. The problem is that it doesn't make a copy there. It still makes a
copy in the original folder and path. The reason I'm trying to put the
copy/backup on drive A is because last week our computer crashed at work and
the place where I worked called in the "Computer Expert" {not me} and wiped
out the hard drive. If that happens again then at lease the file can be
retrieved from the previous backup/copy. The version I would have would be
about 4-6 months old and that means everything would have to be rebuilt.

Your help is greatly appreciated.
Thanks
Try:

strcopyfile = "A:\Copy of " & CurrentProject.Name
I'm using this routine to back up my database. The first part works as is.
What I want to do is to make the copy to A:\ drive.
[quoted text clipped - 149 lines]
End Function
'************* Code End ***************
 
D

Douglas J. Steele

You showed a couple of lines of code showing ways you were trying to set
strcopyfile, and you showed some code you found on "The Access Web". Since
the code from "The Access Web" doesn't use strcopyfile anywhere in it, you
must be planning on altering it in some way.

Incidentally, it's generally not considered a good idea to copy the
currently opened database: there's a chance that it may be in the process of
doing something, so that the copy may be in an inconsistent state. You're
far better copying the file from outside of Access.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Afrosheen via AccessMonster.com said:
Hi Douglas and thanks for your reply. It appears that it is trying to
access
drive A. The problem is that it doesn't make a copy there. It still makes
a
copy in the original folder and path. The reason I'm trying to put the
copy/backup on drive A is because last week our computer crashed at work
and
the place where I worked called in the "Computer Expert" {not me} and
wiped
out the hard drive. If that happens again then at lease the file can be
retrieved from the previous backup/copy. The version I would have would be
about 4-6 months old and that means everything would have to be rebuilt.

Your help is greatly appreciated.
Thanks
Try:

strcopyfile = "A:\Copy of " & CurrentProject.Name
I'm using this routine to back up my database. The first part works as
is.
What I want to do is to make the copy to A:\ drive.
[quoted text clipped - 149 lines]
End Function
'************* Code End ***************
 
A

Afrosheen via AccessMonster.com

Thanks Douglas for the insight. I'll have to look into other options.
You showed a couple of lines of code showing ways you were trying to set
strcopyfile, and you showed some code you found on "The Access Web". Since
the code from "The Access Web" doesn't use strcopyfile anywhere in it, you
must be planning on altering it in some way.

Incidentally, it's generally not considered a good idea to copy the
currently opened database: there's a chance that it may be in the process of
doing something, so that the copy may be in an inconsistent state. You're
far better copying the file from outside of Access.
Hi Douglas and thanks for your reply. It appears that it is trying to
access
[quoted text clipped - 22 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top