I'm relatively new to VBA, but not to programming. I'm trying to set up a shared instance of a class, and I keep running into Run-time error 91, where it complains about the variable not being set.
'A Module which acts as the singleton loader
Private instance As GroceryDatabase
Public Function sharedInstance() As GroceryDatabase
If instance Is Nothing Then
Set instance = New GroceryDatabase 'Run-time error 91 thrown here
Set sharedInstance = instance
Obviously the variable isn't set yet, which is why I'm assigning it a New GroceryDatabase. I've seen a lot of answers to this question that boil down to someone attempting to use a Nothing object, but I can't really understand why this is being thrown when I try to instantiate it.
The error was not specifically due to the line where the object was instantiated, but instead because of an issue in its constructor where there was in fact a variable being assigned but not Set.
This was discovered by putting a breakpoint in the constructor for GroceryDatabase. For the future, I've enabled "Break in Class Modules", found in the path Tools>Options>General. Now, the issue is immediately pinpointed when pressing the "debug" button.