Read module name / form name during error

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Read module name / form name during error

Post by santosm »

Hi All,
Is there a way I can read back the module name and form name that is generating an error? I have error handling code that spits up a message box with the error number and description but I would also like to display the form name (if it is being run on a form) and/or the module name that is firing the error. I am thinking that I may want to start writing these values into a table for later reference.

Thanks,
Mark
Thanks,
Mark

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Re: Read module name / form name during error

Post by santosm »

Hi All,
I found this which will return the active form name. It should serve my needs well.

Code: Select all

Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim frmName As String
frmName = frmCurrentForm.Name
Thanks,
Mark

BenCasey
4StarLounger
Posts: 495
Joined: 13 Sep 2013, 07:56

Re: Read module name / form name during error

Post by BenCasey »

santosm wrote:Hi All,
I found this which will return the active form name. It should serve my needs well.

Code: Select all

Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim frmName As String
frmName = frmCurrentForm.Name
You do not need any code to return the form name.
Both of these will return the form name:
me.name
screen.activeform.name

Access does not expose the module name but it is possible to get it if you hard code it into the error handler for the module, viz:


Code: Select all

Private Sub sGetPostCode
on error goto errhandler
' code here

exithere:
exit sub

errhandler:
select case etc to handle your known cases here for this module
case else ' go to a generic handler with parameters
call errGenericHandler (me.name, "sGetPostCde",err.number, err.Description
end select
resume exithere
End Sub
part from doing that (in each module) you could look at some pseudo calling 'Stacks' For some examples, Google "ms access vba get module name" and have a look at the examples on the StackOverflow.com site.

There is also a commercial product called vbwatch. http://www.everythingaccess.com/vbwatchdog.htm
Regards, Ben

"Science is the belief in the ignorance of the experts."
- Richard Feynman

santosm
3StarLounger
Posts: 253
Joined: 19 Apr 2010, 09:01
Location: Indiana, USA

Re: Read module name / form name during error

Post by santosm »

Thanks Ben,
I will give that a try.

Mark
Thanks,
Mark