[AccessD] File copy or rename/move (was: Export to Excel)

Gustav Brock gustav at cactus.dk
Tue Feb 11 02:30:00 CST 2003


Hi Arthur

> Right you are. Unfortunately, in my most recent environment, this was
> disabled, and I forgot.

Well, no big deal - FileCopy and/or Name As will do:

<code>

    If Len(Dir(strBackFile, vbNormal)) > 0 Then
      ' Delete old target file.
      Kill strBackFile
    End If
    If Len(Dir(strBackFile, vbNormal)) > 0 Then
      ' Old target file could not be deleted.
    Else
      ' Create copy.
      FileCopy strDataFile, strBackFile
      If Len(Dir(strBackFile, vbNormal)) > 0 Then
        booSuccess = True
      End If
    End If

</code>

You can use Name As safely (to rename a file or move it within the
same drive) by wrapping it in similar checks:

<code>

    If Len(Dir(strBackFile, vbNormal)) > 0 Then
      ' Delete old target file.
      Kill strBackFile
    End If
    If Len(Dir(strBackFile, vbNormal)) > 0 Then
      ' Old target file could not be deleted.
    Else
      ' Rename/move file.
      Name strDataFile As strBackFile
      If Len(Dir(strBackFile, vbNormal)) > 0 Then
        booSuccess = True
      End If
    End If

</code>




More information about the AccessD mailing list