- Global Variables:
There are circumstances under which global variables lose their values in Access. These circumstances are not common, but they happen often enough to be of concern. One way around this problem is to create a hidden form with unbound controls, each of which would hold the value of one of your global variables. So instead of using a global variable, you set and reference the value of a control on the form. - Timer events:
If you want run a process at a particular time or multiple times throughout the day, you can create a timer event in a form. This form must be open in order for the timer event to fire. So to keep this form active, but out of the way, you can hide it. - Performance:
Some forms take a long time to load. This may be because it has a large, bound dataset, or it may be a complex form with several subforms. Whatever the reason, once the form is loaded, it makes sense to not close it again.
There are several ways to hide a form. The one you use depends on what you're trying to accomplish.
If you're using the form for global variables or a timer event (or both), the simplest thing is to open it in Hidden mode. To do that, create a macro and name it AutoExec. (see How do I run a macro or code when the database first starts? ). The AutoExec macro is a special macro that will automatically execute when the database opens. In this macro, you'll want to choose the OpenForm action, name the form, and choose Hidden in the Window Mode property.
Like this:
Access 2010-2013
Access 2000-2007
I'll discuss splash screens in a later post.
But once the form is open, it makes sense to hide it rather than close it. To do that, you can use a button. I usually use the button wizard because it creates the button's Onclick event code with error trapping automatically. I use the Form Close wizard, which has a single line of code:
DoCmd.Close
I will replace that with the following:
Me.Visible = False
The next time you "open" the form, it will simply make the already open form visible. So instead of opening a Form, you can instantly by make the form visible and set the focus on it like this:
Forms("MyFormName").Visible = True
Forms("MyFormName").SetFocus
No comments:
Post a Comment