Results 1 to 5 of 5
  1. #1
    ramirezx@ddmfg.com is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    40

    On Error GoTo Line0 Not working the way I want it to work?

    Hi,

    I hope someone can help, I trying to copy files in two different folders from an Access Form, if the file does not exist to GoTo the next Line, for some reason it running all the queries. What I want it to do is if an error occurs to GoTo Line0 and Resume Next skipping the two queries highlighted in RED?

    Is there another On Error I can use that will skip the queries when the file copy error's out. I only want the queries to run if no error occurs?

    Thanks,


    Xavier

    -------------------------------------------------------------

    Private Sub Command0_Click()

    'Device 0, Weld Station 04---------------------------------------------------------------------------------------------------------------


    On Error GoTo Line0
    FileCopy "P:\AccessDB\WeldingData\WeldData\Controls\Channel 0\Device0\dc\welddata_" & [txtFileNameDateTest] & ".csv", "P:\AccessDB\Welding Results\welddata.csv"


    FileCopy "P:\AccessDB\WeldingData\WeldData\Controls\Channel 0\Device0\dc\welddata_" & [txtFileNameDateTest] & ".csv", "P:\AccessDB\Welding Results\DailyCopies\DEV_00_04_" & [txtFileNameDateTest] & ".csv"


    DoCmd.OpenQuery "qry_00c_DEV_00_04_MinWTimeStamp"
    DoCmd.OpenQuery "qry_00c_DEV_00_04_MaxWTimeStamp"


    Line0:
    'This will skip previous lines of code and continue starting on Line0
    Resume Next


    'Device 1, Weld Station 19---------------------------------------------------------------------------------------------------------------


    On Error GoTo Line1
    FileCopy "P:\AccessDB\WeldingData\WeldData\Controls\Channel 0\Device1\dc\welddata_" & [txtFileNameDateTest] & ".csv", "P:\AccessDB\Welding Results\welddata.csv"


    FileCopy "P:\AccessDB\WeldingData\WeldData\Controls\Channel 0\Device1\dc\welddata_" & [txtFileNameDateTest] & ".csv", "P:\AccessDB\Welding Results\DailyCopies\DEV_01_19_" & [txtFileNameDateTest] & ".csv"


    DoCmd.OpenQuery "qry_00c_DEV_01_19_MinWTimeStamp"
    DoCmd.OpenQuery "qry_00c_DEV_01_19_MaxWTimeStamp"


    Line1:
    'This will skip previous lines of code and continue starting on Line1
    Resume Next


    'Device 2, Weld Station 51---------------------------------------------------------------------------------------------------------------


    On Error GoTo Line2
    FileCopy "P:\AccessDB\WeldingData\WeldData\Controls\Channel 0\Device2\dc\welddata_" & [txtFileNameDateTest] & ".csv", "P:\AccessDB\Welding Results\welddata.csv"


    FileCopy "P:\AccessDB\WeldingData\WeldData\Controls\Channel 0\Device2\dc\welddata_" & [txtFileNameDateTest] & ".csv", "P:\AccessDB\Welding Results\DailyCopies\DEV_02_51_" & [txtFileNameDateTest] & ".csv"


    DoCmd.OpenQuery "qry_00c_DEV_02_51_MinWTimeStamp"
    DoCmd.OpenQuery "qry_00c_DEV_02_51_MaxWTimeStamp"


    Line2:
    'This will skip previous lines of code and continue starting on Line2
    Resume Next


    MsgBox ("Import Completed")

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    1) get rid of the resume next. That sends it backwards to the line following the line where the error occured
    2) please use code tags with proper indenting for more than a few lines of code
    3) less important - you could trim out a lot of the repeated verbiage by using variables or sub procedures for repetitive tasks
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    I didn't really do justice with my answer. In fact, it's considered bad form to use goto's to direct flow beyond the norm. Yours is beyond.
    What would be better is to pass the path to a sub procedure, and if that procedure errs, then just exit it. Whether or not you report the error details would be up to you, but I presume you'd still want the other executions of the file copy to occur anyway. Thus you just move on and call the sub again, passing new path parameters.

  4. #4
    ramirezx@ddmfg.com is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    40
    Thanks, I will give it a shot, I was looking in my VBA book for tags, which I couldn't really find anything about tags. I will try the pass to a sub procedure and see what happens?

    I'm getting better with VBA but I still have a long way to go!

    I will let you know what happens!

    Thanks again,
    Xavier

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    To apply the tag here, you use the # button on the toolbar. You could try it out by highlighting all the posted code and clicking it. If you wait too long, you won't be able to edit your post. Maybe just for fun we can compare results between your approach and mine (if I have the time)?

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

Similar Threads

  1. Replies: 3
    Last Post: 05-10-2018, 07:48 AM
  2. On error Goto Problem
    By jtmott in forum Programming
    Replies: 2
    Last Post: 06-17-2016, 09:10 AM
  3. Error Handling Question - On Error Goto
    By redbull in forum Programming
    Replies: 7
    Last Post: 12-06-2012, 07:54 AM
  4. Replies: 7
    Last Post: 12-13-2010, 03:12 PM
  5. On Error GoTo does not resume?
    By easbrandel in forum Programming
    Replies: 5
    Last Post: 04-15-2010, 04:13 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