+ Reply to Thread
Results 1 to 8 of 8

Incorrect error Handling

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Incorrect error Handling

    I have some error handling code that is supose to halt or termintate the program in the case that a file cannot be found - this would happen if the date extension of the file does not exist for the date the user selected via the date picker for a textbox. Unfortunately it does not work correctly and causes the code to run continuously without stopping ( a loop).

    Please see the error handling below, for any suggestions:

    Please Login or Register  to view this content.
    Sub

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Incorrect error Handling

    Take out the on error resume next line.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Incorrect error Handling

    Thanks Dave for suggestion. But that does not work.

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Incorrect error Handling

    Also take out the Resume line. Do you know how Resume works? If not, you need to read up on it before you use your code. It is a dangerous way of ignoring errors instead of really dealing with them.

  5. #5
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Incorrect error Handling

    Dave thanks. I got rid of both lines you said. it still does not work. All I want to do is check to see if the file exist. If it does not a prompt error message should pop-up.

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Incorrect error Handling

    You can check if a file exists using the dir function:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Incorrect error Handling

    Dave thanks. It's not really working, but I am getting closer. It pops up even if the file exist? Not sure whats wrong here.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Incorrect error Handling

    I'd suggest putting a code break (click a red dot onto the left margin) on the If Dir(... line. Then when the code runs, it will stop before executing that line. Next while still in debug mode, go to the immediate window and type Print strFullFileName. Press enter and this will show the path the database expects the file to be at. Next using the windows explorer go to the actual file, copy the path and paste it into the immediate window to compare the two strings. Do they match exactly?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1