Move files and prompt user if overwriting existing file

M

Mike

I have the following code which is using the copy and kill command to
move files from one folder to another. It worked pretty good for
private use, but now I need it in the office and I would need to
prompt the user in case the file already exists.

My code so far:

Private Sub Command9_Click()
Dim strNewName As String
Dim strOldName As String
Dim strtargetfilepath As String

'defines where to look for the target filepath'
strtargetfilepath = DLookup("[Draft to Active]", "filepath")

'takes the name and path of the file of a continuous form'
strOldName = Me.Filename

'adds the old file name to the target filepath'
strNewName = strtargetfilepath & "\" & Me.Name1

FileCopy strOldName, strNewName

Kill strOldName

End Sub

I need something that checks if the new filename (target filepath +
Name1) is already there.

Can anyone help me?
 
D

Douglas J. Steele

If Len(Dir(strNewName)) > 0 Then
' File exists
Else
' File does not exist
End If
 
M

Mike

If Len(Dir(strNewName)) > 0 Then
' File exists
Else
' File does not exist
End If

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)




I have the following code which is using the copy and kill command to
movefilesfrom one folder to another. It worked pretty good for
private use, but now I need it in the office and I would need to
prompt the user in case the file already exists.
My code so far:
Private Sub Command9_Click()
Dim strNewName As String
Dim strOldName As String
Dim strtargetfilepath As String
'defines where to look for the target filepath'
strtargetfilepath = DLookup("[Draft to Active]", "filepath")
'takes the name and path of the file of a continuous form'
strOldName = Me.Filename
'adds the old file name to the target filepath'
strNewName = strtargetfilepath & "\" & Me.Name1
FileCopy strOldName, strNewName
Kill strOldName
I need something that checks if the new filename (target filepath +
Name1) is already there.
Can anyone help me?- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Hi Doug, thanks for the help. I posted my question unfortunately twice
(see URL).
Our IT department had some problems during the day so I couldn't see
what I had already posted and then posted it again.
So here's the URL:
http://groups.google.com/group/micr...?lnk=gst&q=move+files&rnum=6#708eadfd435887b0
Unfortunately I don't know better how to refer to another thread.

Thanks again, Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top