Typo doesn't trigger error handling in Acess VBA - ms-access

After recently adding some new VBA code that referred to a control, my code wouldn't run. On investigation, I found the problem was a typo in the code referring to the control: I'd typed it as Me.CheckYearEmd (with an m) rather than Me.CheckYearEnd.
This is now resolved and the code's working fine, but the weird thing is the error didn't trigger my error handling; it just didn't run. My error handling works on a very simple basis:
On Error GoTo ErrHandler
... 'Rest of sub
Exit Sub
ErrHandler:
DoCmd.SetWarnings True
MsgBox "The database has generated an error. Please contact the database administrator, quoting the following error message: '" & Err.Description & "'", vbCritical, "Database Error"
Is there something specific about referring to a control that doesn't exist (as I effectivley did above) that causes it to bypass error handling, and is there a way of catching these errors?

I can't recreate the situation you described. When I misspell a control name in the form's code, running Debug->Compile from the VB Editor's main menu triggers a compile error: "Method or data member not found".
However, if I don't run Debug->Compile and just try to run the form's procedure with the misspelled name, I still get that compile error.
Although I can't duplicate your situation, I'll offer a guess why the procedure's error handler doesn't catch it. The directive, On Error GoTo ErrHandler, traps run-time errors. But the misspelled control name triggers a compile error.

Related

Access violation, NotEnemy is 0xBF800000

I use cocos2d-x to do the game. After running my program for a while, the variable "NotEnemy" will always report the "access violation" error. NotEnemy is the variable I set in EventListenerPhysicsContact, always using cocos2d-x There will be errors like the title, all I want to know when there is such a mistake, is there any solution, I hope someone can tell me, right, NotEnemy I am assigned this way, auto NotEnemy=contact.getShapeB( )->getBody()->getNode();
I tried setting it to nullptr after using NotEnemy, but it didn't work. Now it generates a new error "Exception at 0x76EE35D2 (located in TankBattle.exe): Microsoft C++ Exception: std::exception, in memory Location 0x00C5F548.
There is an unhandled exception at 0x7640E6EB (ucrtbase.dll) (in TankBattle.exe): A critical program exit has been requested. ", used to be an error about access permissions conflicts, but they are all problems with NotEnemy, and they all appear in the "NotEnemy->SetPosition(Vec2(166,14))" statement.

Invalid Qualifier when using System.IO.path in VBA

I'm extremely new to vba and feel like I have been falling down at the first hurdle all morning. I'm trying to get the path of my access file by doing the following
Sub getDirectoryPath()
Debug.Print (System.IO.path.GetFullPath())
End Sub
However I get an "Invalid Qualifier" error on System when I try to run it. I've tried adding the 'System' reference but then it says IO is not found. What am I doing wrong?
VBA environment has only access to COM (and COM visible) component.
So forget about importing usual .Net namespaces.
But some Wrappers exists : [https://technet.microsoft.com/en-us/magazine/2007.01.heyscriptingguy.aspx]
For instance this works :
DataList = CreateObject("System.Collections.ArrayList")
BTW, in order to parse file full name in VBA, you can use FileSystemObject.

difficulty tracing microsoft access VBA code

I'm new to access and am working with a database someone else wrote.
I'm trying to understand the code by tracing it, but surprisingly I'm having trouble here.
There's a form, let's call it form 1, such that if you click it's "go" button it will execute a procedure. The first command in that procedure is:
DoCmd.OpenForm "Frm2", acNormal
When this line executes it goes to some module, "module X", where two functions are executed. These
functions are in a stand-alone module and I don't see how they are related to Frm2.
After these two functions are executed, control goes to Frm2, specifically this line in Frm2's code:
Form.Load
So, my question, as I alluded to earlier, is why are the two functions in module X called before
control is handed to Frm2?
When the first of the two mystery functions are being executed, I do a stack trace and I see this:
function1()
<non-basic code>
Frm1_Btn_click()
This doesn't tell me what's calling function1, and its throwing me off.
If I comment out function1, I get a run-time error 3085 "Undefined Function
function 1 in Expression". This begs the question, what "expression" is the error referring to?
I believe this is the missing link, but I can't find it.
Thanks for your help
I solved it. The issue was a dependency that was caused by the form having a record source linked to a query. The was due to this.
I'm glad I was able to solve this!

Reproduce MSACCESS.EXE process still running after application exit

Access will sometimes fail to exit cleanly and leave an MSACCESS.EXE process running with no visible user interface (the application is no longer shown in the Applications tab of Task Manager).
What is the minimal code necessary to reproduce this error?
UPDATE: I've posted an answer that reliably reproduces the problem. I would be very interested in other scenarios that may also reproduce the issue. I will upvote any future answer that successfully reproduces the problem. I would like to make this question a repository of verified scenarios that cause the issue so that those who run into this problem in the future have a better explanation then the usual vague suggestions to "close all open objects, etc."
I've searched high and low for a reproducible example of this phenomenon and finally stumbled upon this answer posted by Chris from Brisbane, Australia: Something a little more subtle... I'm reposting his answer here with very slight modification:
Create a new form and add a single command button named cmdShutdown with the following code:
Dim PersistentRS As DAO.Recordset
Private Sub Form_Open(Cancel As Integer)
Set PersistentRS = CurrentDb.OpenRecordset("SELECT * FROM msysobjects")
End Sub
Private Sub cmdShutdown_Click()
Application.Quit ' < This is the culprit.
End Sub
Private Sub Form_Close()
On Error GoTo ErrorHandler
ExitProcedure:
PersistentRS.Close ' < This is all it requires.
Exit Sub
ErrorHandler:
Resume ExitProcedure
End Sub
This problem is not about the PersistentRecordset being left open, quite the contrary.
The fact is that the garbage collector has done its job and has already closed PersistentRecordset.
The garbage collector was called by Application.Quit before the Form_Close event was called.
Any Application.Quit command will call the garbage collector and it doesn’t matter if that command is on another Form.
Once the Application.Quit command has called the garbage collector all variables have been reset.
The Application.Quit command then starts a shutdown sequence.
If any Form is open then an attempt is made to close it.
If the Form has a Form_Close or Form_Unload event those events will fire.
When invoked by the Application.Quit command those events are running with PersistentRecordset which has already been closed.
So, if you are going to look for recordsets which have not been closed then save yourself some time. Look for recordsets where an attempt is made to close them and remove that attempt.
We paid good money for the garbage collector so we should use it; it works.
Trying to do the garbage collection ourselves can lead to failure.
But any such circular error, not just recordset errors, will cause Access to be too busy to close.
Chris.
I confirmed this reproduces the error in Access 2002 running in Windows 7 64-bit.

Handle .NET exceptions within Classic ASP pages

I am making MSSQL stored procedure CLR calls from ASP pages. When an exception occurs, it is logged and then rethrown. In this scenario I need to be able to handle the exception (if possible) in the ASP page. Note that I cannot move away from classic ASP in this instance; I am stuck within a legacy system for this project. Please let me know if you know of a way to handle the exceptions in classic ASP. I appreciate the help!
Thanks,
Tyler
The code language of classic ASP is VBScript, so you have to make do with the error handling capabilities of that language, by using the "On Error ..." construct. You need to decide on whether to make a general error handler or insert some specific error handling logic for the SQL calls.
These are your options for error handling:
On Error Goto 0 ' Turns off error trapping. This is most likely what you got now
On Error Resume Next ' In case of error, simply execute next statement. Not recommended !
On Error Goto <label> ' Go to the specified label on an Error.
If you use On Error Goto ..., The Err object will contain error information. This means you should be able to write somehting like:
On Error Goto errorHandler
' Your code here.
errorHandler:
' Handle the error somehow. Perhaps log it and redirect to a prettier error page.
Response.Write Err.Number
Response.Write Err.Description