0

Anyone else finding that their Terminate() method in Access isn't being called?

Here's my code for my cBusyPointer class with the comments removed for brevity:

Option Compare Database     ' Use database order for string comparisons
Option Explicit             ' Declare EVERYTHING!
Option Base 1               ' Arrays start at 1

Public Sub show()
    DoCmd.hourGlass True
End Sub

Private Sub Class_Terminate()
    DoCmd.hourGlass False
End Sub

Typical usage is:

Sub doTehThings()
    Dim hourGlass As New cBusyPointer
    hourGlass.show()
    ' Do all teh things
End Sub

In previous versions, this class would restore the hourglass whenever the object went out of scope and was destroyed.

I even tried to manually destroy my hourglass object:

Sub doTehThings()
    Dim hourGlass As cBusyPointer
    Set hourGlass = New cBusyPointer
    hourGlass.show()
    ' Do all teh things
    Set hourGlass = Nothing
End Sub

The only way to fix this is to add a hide() method and call that.

Has anyone else encountered this problem?

  • You ask: *Has anyone else encountered this problem?* If I answer yes / no, would that be the answer you are looking for? If not, please edit and the ask the real question for which you want an answer. – Tom Brunberg Feb 07 '22 at 07:10
  • A yes/no will get me started thanks @Tom – Paul O'Neill Feb 08 '22 at 01:18

1 Answers1

1

I cannot replicate the issue. The Terminate() method is called upon reaching the Set hourGlass = Nothing.

A couple of points:

Dim hourGlass As New cBusyPointer

This will create a new instance every time you call the hourGlass variable even to set it to Nothing. See the answer in the link below for additional info:

What's the difference between Dim As New vs Dim / Set

You should always use Dim/Set when working with objects.

hourGlass.show()

This does not even compile in VBA. Subs do not accept parentheses even when arguments are being expected, unless they are preceded with the Call keyword.

Lastly, the cleanest way to reference an object is to access it using the With statement which ensures the object is terminated when the End With statement is reached.

 With New cBusyPointer
     .show
 End With
Kostas K.
  • 8,293
  • 2
  • 22
  • 28
  • This code has worked flawlessly since Access 2013 up to and including Access 2018 but with Access 2021 it fails, specifically build 14872.20158... – Paul O'Neill Feb 08 '22 at 01:15
  • Also, I *want* the busy pointer to show until it falls out of scope so your With New example is not the desired result... – Paul O'Neill Feb 08 '22 at 02:06