.... you need Dir as well to find if the file exists.
A quick example of how this might be implemented
'******************************
Option Compare Database
Option Explicit
Enum RENAME_FILE_RESULT
rfrRenamed = 0
rfrFileNotExist = 1
rfrRenameFailed = 2
End Enum
Function RenameFile(FileName As String) As RENAME_FILE_RESULT
Dim strFileName As String
Dim strExt As String
Dim strNow As String
Dim intInstr As Integer
Dim rfrRet As RENAME_FILE_RESULT
' This determines the format of the date/time string
' you can change this butyou can't include any illegal
' filename charactrs
Const DATE_TIME_FORMAT = "yyyymmdd hh:nn:ss"
strFileName = Trim(FileName)
If Len(Dir(strFileName)) 0 Then
intInstr = InStrRev(strFileName, ".")
If intInstr 0 Then
strExt = Mid(strFileName, intInstr)
End If
strNow = Format(Now, " yyyymmdd hh_nn_ss")
strFileName = Left(strFileName, Len(strFileName) - Len(strExt))
strFileName = strFileName & strNow & strExt
' If you get an error 5 at this point then the format you've
' set for DATE_TIME_FORMAT probably contains
' illegal filename characters
Name FileName As strFileName
If Len(Dir(strFileName)) 0 Then
rfrRet = rfrRenamed
FileName = strFileName
Else
rfrRet = rfrRenameFailed
End If
Else
rfrRet = rfrFileNotExist
End If
RenameFile = rfrRet
End Function
Function TestRenameFile()
' This is a sample call
Dim strFN As String
Dim rfrRet As RENAME_FILE_RESULT
strFN = "d:\text.txt"
rfrRet = RenameFile(strFN)
Select Case rfrRet
Case rfrRenamed
MsgBox "The file was successfully renamed to '" & strFN & "'"
Case rfrRenameFailed
MsgBox "The file '" & strFN & "' was not renamed"
Case rfrFileNotExist
MsgBox "The file '" & strFN & "' does not exist"
End Select
End Function
'******************************
--
Terry Kreft
<pi********@hotmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>
look up format and Date or Now in Help...
now will return a date/time, e.g.
7/31/2006 9:44:33 PM
so you could use format to strip out the spaces and all that fun stuff.
Then just use Name to rename the file.