Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Load a module into memory when an MDE opens

Posted on 2011-03-08
3
Medium Priority
?
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

730 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