473,405 Members | 2,404 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,405 software developers and data experts.

Transactions - Error Handler

patjones
931 Expert 512MB
ADezii,

This is extremely helpful. It's relevant to an issue that I'm having right now in my check tracking database where I have three separate procedure calls to: save employee, save address, save check.

Now, I notice that the .Rollback command is put in the error handler. But in my case, the data processing is taking place inside these various procedures. So if I do this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSave_Click()
  2.  
  3. On Error GoTo Err_cmdSave_Click
  4.  
  5. wrkCurrent.BeginTrans
  6.  
  7. 'Employee not yet in the database
  8. SavePerson
  9.  
  10. 'New employee's address, or update the address to an existing employee
  11. SaveAddress Forms!frmAddOrEdit
  12.  
  13. 'Commit check edits or new check to the table
  14. SaveCheck
  15.  
  16. wrkCurrent.CommitTrans
  17.  
  18. Exit_cmdSave_Click:
  19.     Exit Sub
  20.  
  21. Err_cmdSave_Click:
  22.     MsgBox "Error in subroutine cmdSave_Click: " & Err.Description, vbOKOnly + vbExclamation, "Check Tracking"
  23.     Resume Exit_cmdSave_Click
  24.  
  25. End Sub

...don't I need to put the Rollback in the error handlers for each of the three respective procedures?

Let me know if I need to clarify my situation. Thanks.

Pat

** Edit **
This question pertains to an article (DAO Transaction Processing - What is it?).
Jun 17 '10 #1
4 3670
ADezii
8,834 Expert 8TB
I think what you are looking for are 'Nested Transactions'.
http://support.microsoft.com/kb/177138
Jun 17 '10 #2
NeoPa
32,556 Expert Mod 16PB
Pat, your guess is correct I think. Typically a .Rollback is included in an error handler if, as is generally the case, the transaction should be aborted at that point (as I believe is the case in your code).
Jun 18 '10 #3
patjones
931 Expert 512MB
Thanks!

What I did was to give both the calling and called procedures access to an integer variable (intErrNum) that the called procedure(s) will set to the error number if an error should occur. The calling procedure then checks to see if it has a value or not and does the rollback or commit appropriately.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSave_Click()
  2.  
  3. On Error GoTo Err_cmdSave_Click
  4.  
  5. Set wrkCurrent = DAO.DBEngine.Workspaces(0)
  6. intErrNum = 0
  7.  
  8. wrkCurrent.BeginTrans
  9. blnInTrans = True
  10.  
  11. 'New employee and/or address?
  12. If blnNewPerson Then SavePerson
  13. If blnNewPerson Or blnUpdateAddress Then SaveAddress Forms!frmAddOrEdit
  14.  
  15. 'Commit new check or modifications to the table
  16. SaveCheck
  17.  
  18. If intErrNum = 0 Then
  19.     wrkCurrent.CommitTrans
  20. Else
  21.     wrkCurrent.Rollback
  22. End If
  23.  
  24. Exit_cmdSave_Click:
  25.     Exit Sub
  26.  
  27. Err_cmdSave_Click:
  28.     If blnInTrans Then wrkCurrent.Rollback
  29.     MsgBox "Error in subroutine cmdSave_Click: " & Err.Description, vbOKOnly + vbExclamation, "Check Tracking"
  30.     Resume Exit_cmdSave_Click
  31.  
  32. End Sub
Jun 18 '10 #4
NeoPa
32,556 Expert Mod 16PB
That can certainly work Pat. In the circumstances though, I'd consider triggering an error instead, and have the called procedures set up not to handle errors. It seems to fit the concept of handling errors more naturally than setting values in your code.

I suppose that depends on how you think about code though, so this is just a suggestion. Not to be taken as implying your solution is wrong at all.
Jun 19 '10 #5

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

Similar topics

2
by: Lian Liming | last post by:
Hi, all I want to write my own error handler function in php by using "set_error_handler()" function. I have made a test for this function but found it did not work. My test code is as following:...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
2
by: Steve Richfield | last post by:
My error handler works GREAT. However, VBA seems to have some bugs/features that are causing it fits. The little snippet that I put at the end of each routine looks like this: Error_Handler: If...
3
by: deko | last post by:
I have a logging routine that's supposed to silently log errors caught by error handler code on certain functions. The problem is sometimes stuff happens and the error handler can get caught in a...
2
by: robert d via AccessMonster.com | last post by:
I have a module with an error handler section. At the top of the module is the following statement: On Error GoTo Err_Ctrl In the error handler is a conditional If statement based on an error...
2
by: Lucas Tam | last post by:
Without writing try/catch statements is there a way to have a global error handler in VB.NET? In ASP.NET there is an application level error handler inside Global.asax, but is there something...
10
by: robert d via AccessMonster.com | last post by:
I have a global error handler that up until today has been working flawlessly. Let me first provide the relevant code **************************************************************** On Error...
2
by: Jukka Aho | last post by:
When converting Unicode strings to legacy character encodings, it is possible to register a custom error handler that will catch and process all code points that do not have a direct equivalent in...
2
by: yeghia \(sosy\) | last post by:
Hi Guys I have two questions. 1. Is there a way to set a handler to .NET application so that in case of not caught exception my handler is called before application shutdown. I want to send an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.