Database script public variables

Hello,

I’m trying to set up a database environment in the “Database Script” module. The “Declarations” section does not seem to accept the keyword “Public” in declaring a variable. I’ve tried writing a Class “globalVariables” where vars are declared as “Public”, then linking to that class via a “Use “GlobalVariables”” statement in the “Options” section of the Database Script. This works as the variables are visible in the debugger when the Initialize event of the DBScript fires and I can work with those vars so long as the DBScript is open. However, when the DBScript completes execution and the DB opens to it’s default view, the vars are still displayed in Designer but they have lost their assignments. The DBScript code:


%REM
Database Script Database Script
Created Jan 10, 2017 by Lee Whitney/crc
Description: Comments for Database Script
%END REM
Option Declare
Use “GlobalClasses”
Use “GlobalVariables”
Use “CommonRoutines”
Use “NewObj”

Sub Initialize
Dim session As New notessession
Dim classname As String

Set db=session.currentdatabase
serverName=db.Server

Dim CR As Variant
className=“CommonRoutines”
Set CR=NewObj(className)

Call CR.SetUpDataSourceDB(session,db,dataDB,serverName)
If Not(dataDB.Isopen)Then
MsgBox “Failed to open ““DataDB””.”,32,“Error in DBScript Init event.”
Exit Sub
End If
End Sub


The vars, db, serverName and dataDB are all declared “Public” in the various linked Classes (“Global…”) and the script executes as expected without error. However, any script written in another module “sees” the public vars but they have lost their assignments.

Your ideas are much appreciated.

Lee

Subject: Ahhhh. Bingo!

Mike,

Now I get it. The Database script scope is just that, only available while it’s running. I suppose one could use it to set up a config doc or maybe environmental vars that are available for other modules. I’ll take a different approach and I appreciate your jogging my thinking out of a rut.

Thanks again,

Lee

Subject: Hm. Is that while the DatabaseOpen script is running?

I believe the database script is only running during some scope while the database is being opened. So it loses scope once the database is opened & events move on to somewhere else.