Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Renaming a File (Access 2000)

    I am importing data from a delimited text file into a table.
    Upon completion of the import, I would like to rename the file from
    File.txt to File.old.

    What is the best way to go about this?

    Thanks
    Richard

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Renaming a File (Access 2000)

    If you are in VBA code then use the Name statement.
    Pat <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Renaming a File (Access 2000)

    As Patt suggests using the VB Name statement is simplest way to rename a file. If this is something you are doing on regular basis recommend create generic sub to rename text files with .OLD extension. Example:

    Public Sub RenameTextFile(ByVal strFileName As String)
    On Error GoTo Err_Handler

    ' strFileName must provide full path of file
    ' Note: Can use Name statement to move file to new folder
    ' Assumes file is named *.txt:

    Dim strMsg As String
    Dim strNewFileName As String
    Dim n As Integer

    strNewFileName = Left(strFileName, Len(strFileName) - 4) & ".old"
    Name strFileName As strNewFileName

    Exit_Sub:
    Exit Sub
    Err_Handler:
    Select Case Err.Number
    Case 58 ' File already exists - add number to filename & increment if necessary
    n = n + 1
    strNewFileName = Left(strFileName, Len(strFileName) - 4) & n & ".old"
    Resume
    Case 75 ' Path/File access error (file open)
    strMsg = "The file you are trying to rename (" & strFileName & ") is open. " & _
    "Plz close file and try again."
    MsgBox strMsg, vbExclamation, "OPEN FILE ERROR"
    Resume Exit_Sub
    Case Else
    strMsg = "Error No " & Err.Number & ": " & Err.Description
    Beep
    MsgBox strMsg, vbExclamation, "RENAME TEXT FILE ERROR"
    Resume Exit_Sub
    End Select

    End Sub

    Sub includes error handling for possibility that the *.OLD file already exists (in which case an incremental number will be appended to filename before extension), or the *.TXT file is open. (Interestingly, if the text file being renamed was opened in Notepad, error was not triggered, but if opened in Word, error occurred.) As noted you must provide full path of file being renamed. Example:

    RenameTextFile "C:ACCESSFILE.TXT"

    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •