Thanks Neil,
I think I wasn't clear. When your VBA project gets reset (by a user
clicking [End] in an unhandled error or by stopping the code in the VBE),
all global variables are reset. This includes global variables that hold
object references. I have an object module called UserSession that I want
to have available everywhere throughout my application. So I create it at
my custom login screen and assign it to a global variable declared in a
regular module. It should exist from a succesful login until closing the
application on a given machine. But each time my project gets reset the
object variable gets set to nothing.
I want to be able to assume from all other parts of my application that
UserSession exists, and I don't want to have to embed it in another object
like my login form. I could very easily generate another UserSession if I
could hook into an event that lets me know when the project gets reset.
Otherwise the syntax gets more complex at many many places throughout my
project:
g_UserSession.AddAuditItem ("Something to track")
would have to become:
If g_UserSession is Nothing Then
Forms!frmLogin.CreateUserSession
End If
g_UserSession.AddAuditItem ("Something to track")
I'd have to modify every usage of g_UserSession whether it's a property or
method. But there are some instances where I really want to rely on it
being available without having to check first.
Karim
Neil said:
Karim,
Most people create a 'system' table (just a normal table). In this table you
would probably have at least 2 fields. One for the Record ID and one for the
Value. In your case you could have a row in this table with the record
ID
as
'Reset'. and true/false to indicate the value. Once you have a table set up
then you can use this for anything else that you need to keep a track of
(Has a report printed this week for example). When you need to know if
everything has been reset, you would search the system table for 'Reset' and
check what value is in the value field and then act accordingly.
An alternative to this is to use the Windows Registy using the GetSetting
and SetSetting functions. When doing it this way thoug, information is
stored on an individual computer only.
HTH,
Neil.
variables
and do