![]() |
| Home | News | Products & Services | Downloads | Access Tutorials | Contact Us | ||||||||
SimplyVBA and SimplyVB6 |
![]() | ![]() |
The rest of this page is for those that want to implement this functionality into their own custom error dialog forms or for logging purposes.
In it's simplest form, you can call the VariablesInspector.DumpAll method which returns a String value containing a simple dump of all variable names, data types and current values:
Public Sub MyGlobalErrorHandler()
MsgBox ErrEx.VariablesInspector.DumpAll
End Sub
This would produce something like this:

You can also traverse the call stack and for each procedure in the stack, dump all variables as a string:
Public Sub MyGlobalErrorHandler()
Dim strDump As String
Do
' Header text - module name + procedure name
strDump = strDump & " >> " & ErrEx.CallStack.ModuleName & "." & ErrEx.CallStack.ProcedureName & vbCrLf & vbCrLf
' Dump the variable details from this procedure...
strDump = strDump & ErrEx.CallStack.VariablesInspector.DumpAll & vbCrLf
Loop While ErrEx.CallStack.NextLevel
MsgBox strDump
End Sub
Which might produce:

Taking this a step further - perhaps you want to customize the "dump" into your own format. This is how:
Start by calling the .FirstVar method which ensures we've got a reference to the first variable. Next, loop through the variables using the .NextVar mthod but checking first that we haven't reached the end of the variables list using the .IsEnd method.
Whilst iterating through the variables, use the following read-only properties to identify the variable:
| .Name | string expression of the variable name |
| .TypeDesc | string expression of the variable data type (e.g. 'DAO.Database', 'Long', 'String' etc) |
| .Value | variant copy of the variable value (no matter what data type, all values are coerced into this Variant property) |
| .ValueDesc | string expression of the value. String data types have the double-quotation marks added, 'Object' types are either 'Nothing' or '{Object}' etc. It is advised to use .ValueDesc rather than .Value under normal circumstances. |
| .Scope | enumeration to determine what type of variable this is - One of ParameterVariable, LocalVariable, StaticVariable or ModuleVariable |
| .ScopeDesc | string expression of the .Scope property. One of "PARAM", "LOCAL", "STATIC" or "MODULE" |
An example:
With ErrEx.VariablesInspector
.FirstVar
While .IsEnd = False
strDump = strDump & "(" & .ScopeDesc & ") " & .Name & " As " & .TypeDesc & " = " & .ValueDesc & vbCrLf
.NextVar
Wend
MsgBox strDump
End WithSimilarly, this technique can be used on the ErrEx.CallStack.VariablesInspector instead whilst traversing through the call stack.
Check out the Sample.mdb for an example of using .DumpAll method and also for the advanced method of accessing the variables values (the Developer Access Form example in particular).
| © 2008 iTech Masters. All rights reserved | Access Database Repair | Terms of service | Links | Newsletter |