I would like a button that a user can click on my form, that when clicked copies files from one directory on the network to another. Is this possible and if so how?
I need to copy the contents of a folder (the contents could be anything from 0 to 10 files) and they need to be another folder, overwriting any previous copies. Would your code be capable of this?
Your right, how dumb am I? It didn't work with the old code!
Could you help me with the removal of the original file in the temp folder? Here's the code I tried:
-------------------------------------------
Private Sub cmdtransfer_Click()
Dim objFSO As FileSystemObject
Dim Msg, title, Response, Style As String
Msg = "This option will overwrite older files, do you wish to proceed?"
title = "Warning!"
Style = vbYesNo + vbCritcal + vbDefaultButton2
Response = MsgBox(Msg, Style, title)
If Response = vbYes Then
Set objFSO = CreateObject("Scripting.FileSystemObject"
objFSO.CopyFile Me!OFT_Temp_Folder & "*.*", Me!OFT_Dest_Folder
Set objFSO = Nothing
objFSO.DeleteFile Me!OFT_Temp_Folder & "*.*"
Set objFSO = Nothing
MsgBox "Files succesfully transfered.", vbOKOnly, "Success"
Else:
MsgBox "Operation cancelled.", vbOKOnly, "Cancelled"
End If
End Sub
-------------------------------------------
I get the error 'object variable or with block variable not set'.
Take out the line in red, at the moment you're setting the objFSO to nothing and then trying to use it on the next line hense 'object variable or with block variable not set', because you've unset it.
Dim objFSO As FileSystemObject
Dim Msg, title, Response, Style As String
Msg = "This option will overwrite older files, do you wish to proceed?"
title = "Warning!"
Style = vbYesNo + vbCritcal + vbDefaultButton2
Response = MsgBox(Msg, Style, title)
If Response = vbYes Then
Set objFSO = CreateObject("Scripting.FileSystemObject"
objFSO.CopyFile Me!OFT_Temp_Folder & "*.*", Me!OFT_Dest_Folder Set objFSO = Nothing
objFSO.DeleteFile Me!OFT_Temp_Folder & "*.*"
Set objFSO = Nothing
MsgBox "Files succesfully transfered.", vbOKOnly, "Success"
Else:
MsgBox "Operation cancelled.", vbOKOnly, "Cancelled"
End If
There are two ways to write error-free programs; only the third one works.
I see! I thought that unloaded the current function, in this case CopyFile and then I was loading in the next function. Oh well, it's sorted now. Thanks very much for all your help.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.