Access Forms VBA: Using The IsLoaded Property
Most of the time when developing with MS Access to achieve a really smooth look and feel to your database you will need to eventually code your application and one area where you should start would be with Access forms VBA since end-users will be operating your proud achievements and want to make this a really easy experience for the novice.
With my clients, they like to see something very early on in the development cycle and even though I still need to follow my own planning and designing methodologies, I soon lean towards the front-end namely forms so that my client feels that I’m providing value for money and they can see something really tangible.
If I think of the many times I’ve had to counsel clients during the building phase without seeing any real impact in terms of nice looking screens and other tangible objects – I probably should of added some life coaching time too prior to the project!
Access Forms VBA: IsLoaded Property Wrapped In An If
One aspect of Access forms VBA is to test to see if a form is actually open (or loaded) before interacting with it as it will cause errors. One way to validate this is to introduce the IsLoaded property.
Since you want to test it too, you will need to wrap it into a standard logical if test as follows:
If CurrentProject.AllForms("Customers").IsLoaded = True Then MsgBox "Great!!!, you're open :)" 'Add some real meaningful code here... End If
This can be called from a public sub procedure, function or from an event on a private control like a command button (using the OnClick event).
Just make sure the name of the form (in this example; ‘Customers’) is entered in between the brackets inside double-quotes to respond to a true or false value for the if test to show in this case a simple message box.
Of course you could handle both a true or false response like:
If CurrentProject.AllForms("Customers").IsLoaded = True Then MsgBox "Great!!!, you're open :)" 'Add some real meaningful code here... Else OpenMyForm = MsgBox("Do you want to open?", _ vbQuestion + vbYesNo, "This form is not open!") If OpenMyForm = vbYes Then DoCmd.OpenForm "Customers", acNormal End If End If
If the form ‘Customers’ is not loaded then prompt the user to open it with another if test.
One final point to note about checking Access forms VBA IsLoaded property and that it doesn’t work for sub-forms as this is a controlled by the main form itself (as if it’s a control like a TextBox or CommandButton). You will need to create a custom function to trap for this type of instance but that’s for another time!
Have you spent time looking at VBA functions, properties and their value when automating your application? Need any help? My Access online coaching is a good place to start if you have a project you wish to develop further.