473,320 Members | 1,766 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 question

Alireza355
Dear all,

I have an old (2003) access database with tons and tons of codes for different events and everything imaginable...

I have not used this database for about 10 years now, and now that I went back to it, lots of errors keep popping up because of changes and updates, etc...

For my error handling, I have:

Expand|Select|Wrap|Line Numbers
  1. errorhandler:
  2. MsgBox "Error: (" & Err.Number & ") " & Err.Description, vbCritical
  3.  
So, I get this pop up window, giving me information on the error.

Is there any way I can have access take me to the exact place in the codes where the error has happened? I mean I want to know what was being done when the error happened.

Just a heads up: I have a big form opened, maximized, lots and lots of things happening in the background that make it difficult to know what exactly was being done when the error happened.
Jan 26 '16 #1
8 1212
mbizup
80 64KB
If you are getting 'lots of errors', I'd suggest debugging by temporarily disabling custom error handling.

From the VBA editor, Tools-->Options --> General select the 'Break on all errors' option. With that setting you'll get error popups with a 'Debug' option. Clicking 'Debug' will take you directly to the offending line(s) of code.

If these errors have been in response to Access/Office version changes (with no code changes), the fix may be as simple as updating your references...

Once done debugging, be sure to set the error handling option back to 'Break on Unhandled Errors'.
Jan 26 '16 #2
NeoPa
32,556 Expert Mod 16PB
I would fully support M's advice for this. That is certainly your best course of action.

However, for completeness, there are options that can be run from an error handler that return you either to the line of code that failed or the one immediately after.

Check out the Resume statement. On its own it does the former and with the keyword Next it does the latter.

Let me repeat though, for the situation described you're better off disabling the error handling until you've identified any and all errors in the code.
Jan 26 '16 #3
Thank you mbizup and neopa.

I will give it a try...
Jan 28 '16 #4
ok. the debug is now working and it is taking me to the problem area.

like I said before, I created this database about 10 years ago, with a lot of help from people like you, and now after 10 years of not doing anything "code!!!!" I have forgotten lots of my knowledge.

so the error I am getting right now is "no current record" and debug takes me to:

Expand|Select|Wrap|Line Numbers
  1. Application.RunCommand acCmdSelectRecord
  2.  
I may not have the proper references enabled. I don't even know what references need to be enabled for this line of code to work!!!

what I intended to do was that based on the current record that is currently highlighted or selected in the subform, a dropdown combobox which gets its items from a query would requery and itemdata(0) would be selected and shown.

so the code is actually:
Expand|Select|Wrap|Line Numbers
  1. Application.RunCommand acCmdSelectRecord
  2. [Forms]![sanad]![Combo771].Requery
  3. [Forms]![sanad]![Combo771] = [Forms]![sanad]![Combo771].ItemData(0)
  4.  
but now (after all these years and lots of possible changes or updates) the Application.RunCommand acCmdSelectRecord isn't working.

any ideas???

Thanks a lot.
Jan 28 '16 #5
NeoPa
32,556 Expert Mod 16PB
Hi Ali.

I can't find much on why to use acCmdSelectRecord but it seems that it helps to select the whole record when attempting any record-level actions.

If the error message say "No current record" then it seems that is exactly your problem. I've had similar problems when the recordset's been empty. If that is true in your situation then that should explain why you're getting that message. If there are no records available then selecting the current one is never goiung to work.
Jan 28 '16 #6
Dear Neopa
thank you for your reply. There ARE records and they are shown in the subform. but I get that error. even when I click on another record on the subform, since the code is on its "on current" event, I get the error again and again
Jan 28 '16 #7
jforbes
1,107 Expert 1GB
If the code is being executed in the OnCurrent event, you may want to wrap it in a test to see if you are actually on a record you can use. I use the following to test to see that there is a valid record number, https://msdn.microsoft.com/en-us/lib.../ff821182.aspx:
Expand|Select|Wrap|Line Numbers
  1. If Not Me.CurrentRecord = 0 Then
  2.     'Do the things that need to be done
  3. End If
Jan 28 '16 #8
ok. Today, I spend a couple of hours on my database, and I am beginning to remember what I did 10 years ago.

The reason why I had Application.RunCommand acCmdSelectRecord set on the "on current" event of the subform was that I wanted the whole record to be highlighted at all times.

The reason why it is now giving me errors, I don't know :(

I took it away, and the form and subform are working fine, and no errors are being generated.

I still appreciate your help.
Jan 29 '16 #9

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

Similar topics

0
by: Raaijmakers, Vincent \(GE Infrastructure\) | last post by:
Hopefully posted on the correct newsgroup. The adodbapi group seems so quit.... I want to distinguish between 1) an error in the sql statement to create a table, and 2) when the sql is...
3
by: A.M | last post by:
Hi, I have this code in my web.config: <customErrors mode="On" defaultRedirect="~/ErrorPages/ErrorApp.aspx"> <error statusCode="400" redirect="~/ErrorPages/Error.aspx" /> <error...
4
by: James Radke | last post by:
Hello, I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module...
5
by: Jason MacKenzie | last post by:
I have an application running on Windows Server 2003 that was installed using an MSI package. Every once in a while (maybe once a week), I'll see, by looking at the database that the app is not...
0
by: Jéjé | last post by:
Hi, I'm using the reportviewer to render some reports other the web. this works fine, but sometimes the user could received an error like a session timeout or a data source not found on a...
3
by: Corey B | last post by:
I have added code to my Application_Error sub in Global.ASAX so that whenever an error occurs in my ASP.NET application - it sends me an email with the error information. However the information...
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...
2
by: George Hardy | last post by:
in vs2003, this used to work: try <code> catch ex as exception msgbox "Error: " & ex.message end try in vs2005, this does not seem to throw a message box up, even tho it does make it in...
3
by: =?Utf-8?B?TWFya19C?= | last post by:
I have a usb device that controls a power supply. That usb device must perform a procedure, named Zero_outputs(), in the event of any error. Clearly, within my main form (the only form in this...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.