ActiveConnection not setting object variable

I have a macro that used to work well. Unfortunately, the line

DB = ThisComponent.Drawpage.Forms.getByName(“MainForm”).ActiveConnection

no longer sets the object variable DB. (whenever DB is called, the error message “Object variable not set” pops up.)

I’m running LO 7.0.6.2(x64), and the backend is MySQL 5.7.19. The .odb connection is a MySQL(JDBC).

Is there a better way to get the connection into an object variable?

I think I found my own answer.

DB = ThisDatabaseDocument.CurrentController.ActiveConnection