move files without overwriting

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I have a form displaying external documents (non access) in different
folders.
Folders: Draft, Active, Archive.
I have buttons to move files from the draft to the active folder and
from the active to the archive folder. So far it works pretty fine,
but if someone would put a document in the draft folder which has
already the filename as in the active folder, the new draft file would
overwrite the existing active file. My code actually doesn't show if a
file already exists if one wants to move files from the form.

Here's the code:

Dim strNewName As String
Dim strOldName As String
Dim strtargetfilepath As String
strtargetfilepath = DLookup("[Draft to Active]", "filepath")

strOldName = Me.Filename
strNewName = strtargetfilepath & "\" & Me.Name1

!!! The IF part doesn't work !!! (but I think it shows what I want to
do)
If strNewName = strtargetfielpath & "\" & DLookup("[Name1]",
"documents_tbl") Then
MsgBox "file already exists" = vbCancel
Else
FileCopy strOldName, strNewName

Kill strOldName
End If

Thanks for any help
 
Hi Mike

The following line has strtargetfilepath spelt wrongly...
If strNewName = strtargetfielpath & "\" & DLookup("[Name1]",

If you put...
Option Explicit

at the top of your code (before all the subs & functions) you will be forced
to declare all variables and that helps to spot typos like this one when you
compile.

Hope this helps

Regards

Andy Hull


Mike said:
I have a form displaying external documents (non access) in different
folders.
Folders: Draft, Active, Archive.
I have buttons to move files from the draft to the active folder and
from the active to the archive folder. So far it works pretty fine,
but if someone would put a document in the draft folder which has
already the filename as in the active folder, the new draft file would
overwrite the existing active file. My code actually doesn't show if a
file already exists if one wants to move files from the form.

Here's the code:

Dim strNewName As String
Dim strOldName As String
Dim strtargetfilepath As String
strtargetfilepath = DLookup("[Draft to Active]", "filepath")

strOldName = Me.Filename
strNewName = strtargetfilepath & "\" & Me.Name1

!!! The IF part doesn't work !!! (but I think it shows what I want to
do)
If strNewName = strtargetfielpath & "\" & DLookup("[Name1]",
"documents_tbl") Then
MsgBox "file already exists" = vbCancel
Else
FileCopy strOldName, strNewName

Kill strOldName
End If

Thanks for any help
 
Back
Top