Solved

Load a module into memory when an MDE opens

Posted on 2011-03-08
3
329 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 39

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now