Solved Catch error from Access-In procedure that was started with Appliction.Run (1 Viewer)

Josef P.

Well-known member
Local time
Today, 18:47
Joined
Feb 2, 2023
Messages
847
Does anyone know a way to read out the error text if an add-in procedure was started via Application.Run and this procedure triggers an error with Err.Raise?

Warning: long introduction for a short question, but I think it's necessary.

Starting situation:
The msaccess-vcs-addin can be used to call a procedure before exporting the source files (currently only one procedure within the application).
I modified the export code so that a procedure can be started from an Access add-in. (Note: Both add-ins are executed as a compiled version.)
This allows me to start an automatic test run, for example.
Result:
msaccess-vcs-TestFailedWarning.png


To make this work, I currently set the interface like this:
Public Function AutomatedTestRun(Optional ByRef FailedMessage As String) As Boolean
used in msaccess-vcs-add-in:
Code:
If Not Application.Run(ProcedureName, ExternalReturnErrorMessage) Then
    Log.Error eelLoggedWarning, ExternalReturnErrorMessage, Mid(ProcedureName, InStrRev(ProcedureName, "\") + 1)
End If

This basically works, but I don't like the interface, because although it is suitable for this particular case, it forces you to design every other add-in procedure in the same way.

At first I had the idea of simply triggering an error and passing on the text to be displayed as an error message.
Code:
Public Sub AutomatedTestRun()
  ...
   If Not Success Then
      Err.Raise vbObjectError + 1234, "AccUnitLoader.AutomatedTestRun", FailedMessage
   End If
End Sub
Unfortunately, this does not work.
An error occurs, but the error description is not passed on. (The error number is passed on.)

Does anyone have any idea how I could get the error description?
 
Last edited:

NauticalGent

Ignore List Poster Boy
Local time
Today, 12:47
Joined
Apr 27, 2015
Messages
6,401
Good morning Josef, apologies if this should be glaringly obvious, so you may have to break this down for me, but I am assuming none of the other err properties (.Description, .Source) will do?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:47
Joined
Feb 28, 2001
Messages
27,332
Log.Error eelLoggedWarning, ExternalReturnErrorMessage, Mid(ProcedureName, InStrRev(ProcedureName, "\") + 1)

I did a couple of different searches for the Log.Error function/action but didn't find it. Is that part of an object in a particular library? Is it a method of a custom class?
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 12:47
Joined
Apr 27, 2015
Messages
6,401
It appears to be part of the GitHub version control Add-In...
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:47
Joined
Feb 28, 2001
Messages
27,332
Ah, that 'splains it. I don't have that.
 

Josef P.

Well-known member
Local time
Today, 18:47
Joined
Feb 2, 2023
Messages
847
.. but I am assuming none of the other err properties (.Description, .Source) will do?
Unfortunately not.
I created an example.

GitHub version control Add-In...
I have now added a link in the 1st post.
 

Attachments

  • AppRunTest.zip
    68.5 KB · Views: 69

NauticalGent

Ignore List Poster Boy
Local time
Today, 12:47
Joined
Apr 27, 2015
Messages
6,401
Unfortunately, McAfee wont let me open it...

1710337651502.png
 

Josef P.

Well-known member
Local time
Today, 18:47
Joined
Feb 2, 2023
Messages
847
Now without vbs file:
 

Attachments

  • AppRunTest.zip
    53.6 KB · Views: 28

Josef P.

Well-known member
Local time
Today, 18:47
Joined
Feb 2, 2023
Messages
847
To end this thread: I did some more research, but couldn't find a way to pass on an error including the error description.
Note: I marked the thread as "Solved", even if the problem is not solved. But there is no such thing as unsolvable as a final marker. ;)

What else I noticed during testing:
If the add-in is not compiled and the error is triggered with Err.Raise, the code execution stops in the add-in code. So you can only catch the error in the calling procedure if the add-in is compiled (accde).
 
Last edited:

Users who are viewing this thread

Top Bottom