0

Hopefully this is a simple question, though the solution may not be. In MS Access, is it possible to instantiate a VBA class in the application or database scope?

What I want to do is persist a WinHttp instance with the same lifetime as the application or database so that as various Form Event handlers call a web service, they can do so using a persistent session object.

If not, it seems like I'll always need to grab and persist the session state, particularly the JSESSIONID, before the current instance goes out of scope and then quietly put it back on the next instantiation. This is coming up because I really can't afford the authentication overhead on the client or the server.

What would be the recommended way to maintain a physical or virtual persistent session across multiple Form Events?

tlum
  • 913
  • 3
  • 13
  • 30

1 Answers1

-1

Yes, this certainly is possible. Just dim it in a module outside of any sub or function (without the New keyword)

Public winHttpObj As Object

Public Sub CreateWinHttpObj
   Set winHttpObj = CreateObject("WinHttp.WinHttpRequest.5.1")
End Sub

You can refer to it from the same module, or from any other module by using the ModuleName.Variablename notation

If it's desirable is a whole different question.

Erik A
  • 31,639
  • 12
  • 42
  • 67
  • I actually regret asking the question, but I'll leave it for it's answer value. What I really needed was an AutoExec Macro to call a startup function so it was already instantiated before the first click event. But this is actually not desirable, what I really need is "Form Scope" now that I think about it. Server and session are unique to the form and should live and die with it. – tlum Jan 27 '18 at 19:25