Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Name that file already! (Access 97 SP2)

    I have been reoutinely using Name to rename .txt files for several applications. My problem is that one of our outside entities is supplying us with a file that we'd like to upload to our main system and the file name they've chosen is something like this:

    Mickey9393.030507.04404.txt

    Since there are 3 dots in the name instead of what we're used to with other entities (mickey939303050704404.txt), I'm trying to figure out a way to use Name to rename this file to something we can work with. I can't get the outside entity to change their ways and I'm trying to automate this process as much as possible so that the end user doesn't have to manually go in and do anything.

    Any suggestions? <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29> My apologies if this has been discussed before...
    Carpy Diem, it&#39;s .

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Name that file already! (Access 97 SP2)

    You could use this function to remove all periods exept the one before the extension from the file name:

    Function NewName(strOldName As String)
    Dim strNewName As String
    Dim i As Integer
    ' Remove extension
    strNewName = Left(strOldName, Len(strOldName) - 4)
    ' Loop to remove periods
    i = InStr(strNewName, ".")
    Do While i > 0
    strNewName = Left(strNewName, i - 1) & Mid(strNewName, i + 1)
    i = InStr(strNewName, ".")
    Loop
    ' Append extension again
    NewName = strNewName & Right(strOldName, 4)
    End Function

    Use it like this:

    Dim strFileName As String
    strFileName = "Mickey9393.030507.04404.txt"
    Name strFileName As NewName(strFileName)

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Name that file already! (Access 97 SP2)

    Thanks, Hans! I'll try it out and let you know how it goes (probably not 'til tomorrow, though)...
    Carpy Diem, it&#39;s .

  4. #4
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Name that file already! (Access 97 SP2)

    Hans - I got it to work if the user types in the file name. Now I'm trying to figure out what the minimum amount of information I can have them put in since some of the file name attributes are the same. I tried to do DIR() to get the file name, but then the Name() didn't work. But it's definitely better than having the users (<IMG SRC=http://www.wopr.com/S/shocked.gif alt="AAAARRRGGGGHHHH"> ) open the file, delete the first and last line, close the file, rename the file and then move it. <IMG SRC=http://www.wopr.com/S/flee.gif alt="Not my idea of fun!">

    Thanks for your help! <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    Carpy Diem, it&#39;s .

Posting Permissions

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