-
Hi Guys
I made a post yesterday about a piece of code I was having trouble
understanding. It used an api function SHFileOperation
Heres the code
Public Function MakeBackUp(ByVal bvDatabase As Database, ByVal bvBackupDatabase As String) 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 MakeBackup_Err
If DBExclusive(bvDatabase) = True Then
Err.Raise cERR_DB_EXCLUSIVE
End If
lngFlags = FOF_SIMPLEPROGRESS Or _
FOF_FILESONLY Or _
FOF_RENAMEONCOLLISION
******************************************************
strSaveFile = CurrentDBDir & bvBackupDatabase & ".mdb"
With tshFileOp
.wFunc = FO_COPY
.hwnd = hWndAccessApp
.pFrom = bvDatabase.Name & vbNullChar
.pTo = strSaveFile & vbNullChar
.fFlags = lngFlags
End With
lngRet = SHFileOperation(tshFileOp)
MakeBackUp = (lngRet = 0)
*******************************************************
MakeBackup_End:
The bit between the * is the part I think should come out, or rather I
was advised by Jop. He said to put this in :
Public Function MakeBackUp(ByVal bvDatabase As Database, ByVal bvBackupDatabase As String) As Boolean
******
If DBExclusive(bvDatabase) = True Then Err.Raise
strSaveFile = CurrentDBDir & bvBackupDatabase & ".mdb"
FileCopy bvDatabase.Name & vbNullChar, strSaveFile & vbNullChar
*****
'This just copies the file... that's all what the other code does right?
End Function
I have no idea what my code is trying to do ( I have taken this app over from someone who has
left the company) could someone talk me through what the api is trying to do.
what does the tshfileop bit do !
If it as simple as what Jop said why would anyone complicate it in this
way ? ( BTW I dont doubt your suggestion for one minute Jop ) I just need an explanation of
what is happening, I am nervous about removing bits of code that are
already there and screwing up the prog as it is buisness critical.
If I put Jops suggested solution in do I still need the lines
lngRet = SHFileOperation(tshFileOp)
MakeBackUp = (lngRet = 0)
I have also found this type declared in the dec part of this module which is related to the code above
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
Thanks for your previous help and any given today
Locutus
[Edited by locutus on 11-02-2000 at 05:59 AM]
-
I have emailed you some details from MSDN about the SHFileOperation function. Unfortunately that is the best I can do. Hope this helps.
-
anyone else
anybody else shed some light on this for me ?
-
use debug tools...
put a break on the the first line:
Code:
If DBExclusive(bvDatabase) = True Then
and single step <F8> function key through the program
to see what is happening...
-
Hey lotocus, I hope you already got the solution, but what I was trying to say was that you don't need to add it, but replace the code you already had with mine.
But ehrm.. just comment all your other code (click View > Toolbars > Edit and look at the button with the lines, you can use that to comment code fast) and insert my code, you'll notice that it does the same (if I didn't overlooked something)... as a safety consideration just make a backup before beginning.
Oh and never use code (from others) you don't understand, first go trough each line and try to understand it. If you don't understand it write it down, then when you're done with the code, come to this forum and post the code and bold out the code you don't understand and we're happy to help you (at least I am)
[Edited by Jop on 11-03-2000 at 11:46 AM]