Trapping Reset Project

  • Thread starter Thread starter Karim Virani
  • Start date Start date
K

Karim Virani

I'm having that annoying problem where a reset project clears all global
module variables. I want to be able to trap when an Access2K project has
been reset so that I can run some code to re-initialize these variables and
restart quiescent objects. There don't seem to be any hookable events in
the CurrentProject or Application objects that would help me out. How do I
do this?

Thanks

Karim
 
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.
 
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
 
Karim,

You could trap the error:

Private Sub SomeProc
On Error Goto Err_SomeProc

' Statements go here

Exit_SomeProc:
' Exit the sub
Exit Sub

Err_SomeProc:
' Check the error
Select Case Err
Case 91 ' From memory, I think this is the error you get when an
object has not been set
' Call procedure to re-initialise variable(s) and try again
Resume 0
Case Else
' This is an unknown error - Display and exit
MsgBox Err.Description, vbOKOnly + vbCritical, "Error " & Err
Resume Exit_SomeProc
End Select
End Sub

A good db will never show the End/Debug screen as all errors should be
handled gracefully. Even if (like above) a message is displayed and then the
database is closed for example so the the user has to re-open the database,
then some form of resetting is guaranteed to happen. Fustrating for the user
but easier to debug problems.

HTH,

Neil.

Karim Virani said:
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
 
Back
Top