Set A Public Variable In Another Database To True

frmla77

New member
Local time
Today, 17:35
Joined
Apr 8, 2015
Messages
9
Is it possible to open another database, set a Public boolean variable in a module?

in db1: Open database by Access.Application, OpenCurrentDatabase, setting obj to db2.CurrentProject, loop through main objects

in db2: Public ByPassCloseVar As Boolean is in a module ModLinkTblReview

I have a process that opens up a database runs through all of its objects to get their properties and values. There is a form that is set up on Unload to close the tool if the variable is set to False. When I open the form to get the properties and their values, then close the form, it closes the database. I would like to set the variable to true in order for the database to stay open.

Thought something like this would work:
db2.Modules!ModLinkTblReview.ByPassCloseVar = True

Indicates that method or data member does not exist.

Suggestions?

Thanks
 
Last edited:
@Rx:

I am sorry, I do not understand the reply. I see nothing on the list that could help unless I am missing something. What would be used to get to the module variables?

I have access/control to the second database, but unable to see, get or set a variable.
 
What, do I have to draw you a photo... Oh, looks like I did anyway :D
First create a blank Access DB daved it as C:\MyTest\MyTestDB1.accdb
Second, add a module to it, created one Public variable MyTestDb1PublicVariable as Boolean
Save and close

In my regular Access DB, open any module.
In Tools References - Browse (set filter to Access file type) and find the MyTestDB1.accdb in C:\MyTest
Choose, then select the check box.

The F2 key brings up the Object Viewer and the Object Payne also shows MyTestDB1 and the objects.

In the Immediate Window (since we don't want to wait)
Print the current value of MyTestDbPublicVariable (see False returned)
Assignt the variable to True
Now Print the current value and see that it changed to True

That should get you started

The secret is not to stay young. The secret is to get old, very old.
 

Attachments

  • Reference 2nd Access Database with Public Variable.jpg
    Reference 2nd Access Database with Public Variable.jpg
    99.9 KB · Views: 105
It doesn't make sense to me to set a global VBA variable in a different database. That variable only has scope within that database, so there is no mechanism by which that variable's value would be persisted in any way. What makes more sense to me is store a value in a table, which is what a database is for. Then, write code that gets or sets that value, either in that local database, or where ever. Other than that, global variables are a sort of bad idea even in the application you are currently using, let alone in a remote one, whereas storing data in a table is brilliant, simple, immediate, persistent, searchable, sortable, documentable, everything a global variable is not.
 
Yes Mark, I can agree with you on this.
While my DB has many Linked SQL Server Tables, there are some Local tables used just for persisting values.
For some persisted data there is the Resistry Key option to create a new key in the Registry for things like the User color scheme.

Perhaps FrmLA77 can provide more facts as to why this was requested.
As you see the Rx just blindly filled the Prescription, it didn't suggest it was the cure.
 

Users who are viewing this thread

Back
Top Bottom