Quote:
>My Public Variable get cleared when an error occurs!
<snip>
>Anyone know what's up with this? How can I trust a global/public variable
>if it can be reset by an error? I've trapped the error and get the same
>results!!
This is known behavior and by design. It happens on *unhandled* errors.
This is probably the main reason why it's not recommended to use public
variables. One workaround is to use public properties in standard module,
which can be made self-fixing, instead of public vars:
Private dbC As DAO.Database
Public Property Get dbCur() As DAO.Database
If dbC Is Nothing Then
'something reset the var or it hasn't been set yet
Set dbC = CurrentDb
End If
Set dbCur = dbC
End Property
Another approach is to use Properties collection of the database to store
globally available values. Those will persist even between sessions.
--
(remove a 9 to reply by email)