473,320 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Error handling tweak

DJRhino1175
221 128KB
Expand|Select|Wrap|Line Numbers
  1. Private Sub DatabaseUpdate_Click()
  2.  
  3.    On Error GoTo Edit_Rates_Error
  4.  
  5.     Dim strPath     As String
  6.     Dim strFromFile As String
  7.     Dim strToFile   As String
  8.     Dim db          As DAO.Database
  9.     Dim rstFileList As DAO.Recordset
  10.  
  11.     strPath = "G:\Unsecure-Share\New OEE System\"
  12.  
  13.     strFromFile = strPath & _
  14.         "Data Tables\OEE Database v1.0 - Admin.accdb"
  15.  
  16.     Set db = CurrentDb
  17.     Set rstFileList = db.OpenRecordset("DBUpdater", dbOpenDynaset)
  18.     With rstFileList
  19.         If Not (.BOF And .EOF) Then
  20.             rstFileList.MoveFirst
  21.             Do While Not .EOF
  22.                 strToFile = strPath & rstFileList!SendTo
  23.                 Call FileCopy(strFromFile, strToFile)
  24.                 .MoveNext
  25.             Loop
  26.         End If
  27.         .Close
  28.     End With
  29.     db.Close
  30.     Set rstFileList = Nothing
  31.     Set db = Nothing
  32.  
  33.     DoCmd.Quit
  34.  
  35. Edit_Rates_ExitHere:
  36.     Exit Sub
  37.  
  38. Edit_Rates_Error:
  39.    If Err.Number <> 70 Then
  40.      MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
  41.    End If
  42.    Resume Edit_Rates_ExitHere
  43.    Resume
  44.  
  45. End Sub
Instead of exiting the sub, is it possible to do a move next? I tried using .Movenext in several different areas of the code, but each time it would not compile. So I guess I'm missing something that will make this happen. This code works as it should but instead of stopping when it encounters error# 70 I would like it to go to the next record until complete.

Thanks for any help.
Mar 29 '19 #1

✓ answered by twinnyfo

DJ,

You have the right idea here, with checking to see if the Error is a specific error. I assume that if it is Error 70, that you don't want the code to stop, but continue?

In that case, your EH sub would look like this:
Expand|Select|Wrap|Line Numbers
  1. Edit_Rates_Error:
  2.     If Err.Number = 70 Then
  3.         Resume Next
  4.     Else
  5.         MsgBox Err.Description, _
  6.                vbExclamation, _
  7.                "Error #: " & Err.Number
  8.         GoTo Edit_Rates_ExitHere
  9.     End If
  10. End Sub
The Resume Next just picks up the code in the place that caused the error and moves to the next line. You must be careful with such a set-up, though, because some errors are caused because the code can't continue. But with prudent usage, this is a perfectly normal method of doing things.

Hope this hepps!

2 1093
twinnyfo
3,653 Expert Mod 2GB
DJ,

You have the right idea here, with checking to see if the Error is a specific error. I assume that if it is Error 70, that you don't want the code to stop, but continue?

In that case, your EH sub would look like this:
Expand|Select|Wrap|Line Numbers
  1. Edit_Rates_Error:
  2.     If Err.Number = 70 Then
  3.         Resume Next
  4.     Else
  5.         MsgBox Err.Description, _
  6.                vbExclamation, _
  7.                "Error #: " & Err.Number
  8.         GoTo Edit_Rates_ExitHere
  9.     End If
  10. End Sub
The Resume Next just picks up the code in the place that caused the error and moves to the next line. You must be careful with such a set-up, though, because some errors are caused because the code can't continue. But with prudent usage, this is a perfectly normal method of doing things.

Hope this hepps!
Mar 29 '19 #2
DJRhino1175
221 128KB
Thanks Twinn
Error 70 is a permission error, meaning someone has it open, so if I get error 70, bypass and move on to the next one...

Ran through it and it works perfectly.

Thanks again.
Mar 30 '19 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: WSeeger | last post by:
When creating a new class, is it encouraged to always include error handling routines within your LET and GET procedures? It's seems that most text books never seem to include much about error...
12
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
21
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So...
3
by: Stefan Johansson | last post by:
Hi all I'am moving from Visual Foxpro and have a question regarding "best practice" error handling in vb .net. In VFP I have always used a "central" error handling object in order to have a...
4
by: Al Williams | last post by:
Hi, I have error handling in place throughout my application. I also start the application wrapped in error handling code to catch any unexpected exceptions (i.e. exceptions that occur where I...
1
by: Metal Dave | last post by:
I do not understand the error handling of SQL Server here. Any error in bulk insert seems to halt the current T-SQL statement entirely, rendering it impossible to log an error. The first statement...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
1
by: pob | last post by:
>From a form I have some code that calls 4 modules frmMain 1 mod 2 mod 3 mod 4 mod If mod 1 experiences an error the error handling works fine within mod 1 and writes out the error to a...
35
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
0
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.