Solved

Load a module into memory when an MDE opens

Posted on 2011-03-08
3
361 Views
Last Modified: 2012-05-11
I have a number of Variables that are constant during the use of a program that is in the form of a MDE.  Right now I load them as "OnOpen in a form or report and then the program kills the set of variables each time the form closes.  In some cases I open a form with all the information stored in fields, minimize it and then use me!FieldName to access the data but it seem wrong to me.  On top of that the program is doing more and more and the form itself is getting slow to load as I add more to it.

At one point  I used a program where you created a module called Autoexec, and it loaded all the variables / calls that you needed just like dos or novell does, that would be the best example of what I want to do in VBA.

What I would want is these to be stored as public variables so  they would not be destroyed until the program closes.  I just do not know how to do it, if you could point me to any documentation that would enlighten me that would be a great help.
0
Comment
Question by:mdlp
3 Comments
 
LVL 40

Assisted Solution

by:als315
als315 earned 200 total points
ID: 35079773
You can declare these variables in module (Insert - Class Module):

Option Compare Database
Option Explicit
Global MyString As String, MyNumber As Integer
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 300 total points
ID: 35082912
<<What I would want is these to be stored as public variables so  they would not be destroyed until the program closes.  I just do not know how to do it, if you could point me to any documentation that would enlighten me that would be a great help. >>

  You would declare the variables as als315 said, but typically you'd use a standard module rather then a class one.  You'd delcare them as Public or Global in the declartions section at the top of the module.

  You can certainly write classes and then create an instance of a class when the DB opens, but that's probably more then you want (or need) to do.

  With Access, a marco called 'Autoexec' will get executed when the DB opens unless the shift key is held down (or you have turned off the shift key by-pass).  So you can call a procedure from there with the RunCode action to initialize your variables.

  Your other option is to specify a startup form and then from the forms OnOpen event, call the procedure to init the variables.

JimD.
0
 

Author Closing Comment

by:mdlp
ID: 35083246
als315, thank you I did not know about global declares.

JDettman, Thank you for your suggestion about the differences in the calsses and a module.  I did not know about the "autoexec" macro, that might be exactly what I need.

Thank you both, you have allowed me to move this project to the next level.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question