Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Load a module into memory when an MDE opens

Posted on 2011-03-08
3
Medium Priority
?
385 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 800 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 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 1200 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

927 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