I am coding VBA in Access 97. I want a functionality that would move a file(entered by input) from a know directory to another know directory.
From artile "HOWTO: Use the Animated Copy Functions in Windows 95/98" in MSDN, I have modified its code to form what I called a moveFile function which takes in the filename(entered by input) and the Form from which the function is initiated.
As you see, the code from MSDN uses Windows API, and it is not 'neat'. Ideally, I want to manipulate the Files/Directories as objects, but I can't find any Object libraries (Explorer,File MAnager, File, etc. etc.) that would allow me to do just that.
When I attempt to run the following code, I received error "File blahblah could not be found, etc. etc."
I can't debug it!!
Could anyone see what's wrong with this??
Just now, I found something called 'FileSystemObject' for VB, but When I attempt to type:
, FileSystemObject does not get recognised by VBA in Access!!!!
The file I need to move is actually Excel97 file, would that be OK?? What object libary do I need to move files with this object?
[sig][/sig]
From artile "HOWTO: Use the Animated Copy Functions in Windows 95/98" in MSDN, I have modified its code to form what I called a moveFile function which takes in the filename(entered by input) and the Form from which the function is initiated.
As you see, the code from MSDN uses Windows API, and it is not 'neat'. Ideally, I want to manipulate the Files/Directories as objects, but I can't find any Object libraries (Explorer,File MAnager, File, etc. etc.) that would allow me to do just that.
When I attempt to run the following code, I received error "File blahblah could not be found, etc. etc."
I can't debug it!!
Code:
Public Sub moveFile(fileName As String, theForm As Form)
Dim lenFileop As Long
Dim foBuf() As Byte
Dim fileop As SHFILEOPSTRUCT
Dim result As Long
lenFileop = LenB(fileop) ' double word alignment increase
ReDim foBuf(1 To lenFileop) ' the size of the structure.
MsgBox homeDir & "hold\" & fileName
With fileop
.hwnd = theForm.hwnd
.wFunc = FO_MOVE
.pFrom = homeDir & "hold\" & fileName
.pTo = homeDir & "open\" & fileName
.fFlags = FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or _
FOF_NOCONFIRMMKDIR
End With
' Now we need to copy the structure into a byte array
Call CopyMemory(foBuf(1), fileop, lenFileop)
' Next we move the last 12 bytes by 2 to byte align the data
Call CopyMemory(foBuf(19), foBuf(21), 12)
result = SHFileOperation(foBuf(1))
'If result <> 0 Then ' Operation failed
' MsgBox Err.LastDllError 'Show the error returned from
' 'the API. Else
' If fileop.fAnyOperationsAborted <> 0 Then
' MsgBox "Operation Failed"
' End If
'End If
End Sub
Just now, I found something called 'FileSystemObject' for VB, but When I attempt to type:
Code:
Dim theFileObj as new FileSystemObject
The file I need to move is actually Excel97 file, would that be OK?? What object libary do I need to move files with this object?
[sig][/sig]