Results 1 to 8 of 8
  1. #1
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56

    Renaming Files- Name already exists Error Handling solution

    I am using the code, Rename "Name1" As "Name2" as part of a renaming and sending procedure. I am using a program generated naming convention for Name2. Is there a simple solution to compare if Name1 and Name2 exist before the error handler spoils everything if indeed there already is a file by the same name. As I have the full file paths for both names, would it be as simple as If Name1 = Name2, then msgbox "Name Already exists" and End, else continue. Everything I've looked at seems to want to create a separate function, or others say use FSO (though there seems to be a vehement debate about using FSOs). There must be a basic solution without adding further declarations and functions to my code. You probably gathered that I'm not a programmer, but any direction or resources would be appreciated.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    You can use the Dir() function to see if the file exists already.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56
    Very Cool! It took me a while to find it, but here it is in all its simplitic glory doing what I need it to do. Thanks pbaldy for pointing me in the right direction.

    Code:
    'Check if file exists
                
    If Dir(NNPath) <> "" Then
     
                    MsgBox "File Already Exists!!! Please check Your Files"
     
                        'Else
     
                            'MsgBox "No Go!"
                               
    
                                End  ' I added this so it will go no further
                                End If

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56
    Initially I was looking for a method of checking to see if a folder exists so that when renaming, you will avoid having 2 folders with same name, and causing an error. The code certainly does that. But I also need to see if the file exists, not for duplicate file purposes, but if it does, then bypass renaming and go to the send procedure. Is there a method to distinguish between duplicating files as opposed to just the one file with the same name?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    Sorry, but I don't understand what you're asking. You can use the function to see if a directory or file exists, and respond accordingly with your code logic.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Carouser is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Location
    Melbourne, Australia
    Posts
    56
    Dir() is doing what it is supposed to do, and I realized what I am asking has everything to do with error handling which, admittedly, is on my learn to do list. Thanks Paul and onwards on the db journey.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    Here are the basics of error handling:

    http://www.baldyweb.com/ErrorTrap.htm

    But I'm of the school of thought that thinks you should prevent errors from happening when you can foresee them. I don't understand what problem you're having with Dir() that error handling will catch.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. On Error handling
    By rivereridanus in forum Access
    Replies: 2
    Last Post: 06-18-2012, 07:46 AM
  2. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM
  3. Error Handling
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 09-14-2010, 12:17 PM
  4. Error Handling
    By trb5016 in forum Access
    Replies: 2
    Last Post: 08-10-2010, 08:37 AM
  5. Checking if files exists
    By geoffishere in forum Access
    Replies: 1
    Last Post: 02-09-2010, 01:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums