|
-
Nov 1st, 2000, 09:38 AM
#1
Thread Starter
Hyperactive Member
I have recently taken over a VBA app. I have never done VBA before only VB hitting an access database.
The VBA / access prog works fine on the users machine and has been running for a number of months. When I run the app on my machine ( where I have VB 5 installed )it bombs out here.
Private Declare Function apiSHFileOperation Lib "Shell32.dll" _
Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) _
As Long
the sub that creates a new .dat file for output bombs out and highlights the above code in a module.With the error message : user defined type not defined
I looked in my VB5 API text viewer and couldnt find a match for apiSHFileOperation but there was one for SHFileOperation
so I took the api of the start of the private declare function so it now looks like this:
Private Declare Function SHFileOperation Lib "Shell32.dll" _
Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) _
As Long
this now allows the creation of the file and it appears in the correct directory on my HD. Is this something to do with VBA and VB5 being different development platforms. Why does it work with the the API prefix on the users machine and not on mine ? can anyone explain this to me ?. And when I give the prog back to them ( I am making some minor changes to it ) will it now not work on thier machine until I put the api prefix back on where I took it off on mine.
Does this make sense ?.
part two ( groan )
straight after creating the file the prog goes to another sub called make back up :
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
******************** again here I took out the api in front
******************** of the SHFile...
********Now the program stops at this line with a message ********about memory
***stops here** lngRet = SHFileOperation(tshFileOp)
MakeBackUp = (lngRet = 0)
MakeBackup_End:
Exit Function
MakeBackup_Err:
MakeBackUp = False
Select Case Err.Number
Case cERR_USER_CANCEL:
'do nothing
Case cERR_DB_EXCLUSIVE:
MsgBox "The current database " & vbCrLf & bvDatabase.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: MakeBackup" & vbCrLf
strMsg = strMsg & "Description: " & Err.Description & vbCrLf
strMsg = strMsg & "Error #: " & Format$(Err.Number) & vbCrLf
MsgBox strMsg, vbInformation, "MakeBackup"
End Select
Resume MakeBackup_End
End Function
The error message is as follows:
MSAccess.exe appliucation error
The instruction at "0x77f34cab" referenced memory at "0x01900000" the memory could not be "read"
Any idea's what this means or what could be causing it ?
Help me OB1 , your my only hope.
Thanx
Locutus
-
Nov 1st, 2000, 09:51 AM
#2
Frenzied Member
hmmm.. I think the API is a bit to complicated for this stuff, you could also use
Code:
Name 'move (also rename) the file
FileCopy 'Copy a file
Kill 'Delete a file
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 1st, 2000, 09:59 AM
#3
Guru
Help me OB1 , your my only hope.
Naaaa, there's also Jop and Yonatan. 
Code:
Name "OldName" As "NewName"
Call FileCopy("Source", "Destination")
Kill "VictimFile"
The only situation where the API is preferred for those operations, is if you want to display the Windows copy/move/delete dialog.
If you really need the API...
Code:
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String
End Type
-
Nov 1st, 2000, 10:16 AM
#4
Thread Starter
Hyperactive Member
thanks for the reply......
Thanks for replying guys but.....
could you explain a wee bit more.
I have only ever used a little api before.
Why would anyone use this api for such a simple task, there are only two subs that are involved with file handling. The first sub simply opens a file for output and writes records to a file. The second sub is the one above, but I dont understand what is going on in the above code.
lngRet = SHFileOperation(tshFileOp) , I have no idea what this means or how to take it out and do what you guys suggested. Do I need this ? please could you explain a little more for me. ( sorry, but I don't do much VB and am a bit of a newbie)
Locutus
-
Nov 1st, 2000, 10:26 AM
#5
Frenzied Member
That line is for the API, you don't need it if you just use Name FileCopy & Kill:
Code:
'Here's your code modified and simplified ;)
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
Maybe I overlooked some stuff, i'm in hurry
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|