Solved

Load a module into memory when an MDE opens

Posted on 2011-03-08
3
374 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 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 58

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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

615 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