Managing Multiple Form Instances

AccessInsider demonstrates the collection method of managing multiple instances of a form. Free example database included.

Referencing Access Objects in a Query or Control

Referencing data in objects (tables, forms, queries, reports) is a basic skill in the Microsoft Access developer's toolkit, but what if you need to reference the objects themselves as part of a custom administrative interface (for example)? AccessInsider demonstrates one method of accomplishing just this.

Concatenating Fields in an Access SQL Query

Having trouble combining multiple fields in a query or not sure when you use the + symbol instead of an ampersand? AccessInsider shows you how.

Setting Parent/Child Form Windows

Learn how to load a form inside another form as a child window. Free example database provided by AccessInsider.

Cascading List Boxes: Part 1

This article will demonstrate how to create cascading list boxes between tables with one-to-many relationships.  The example provided here has been created by the author using Microsoft Access 2007.  This method also modified to work with combo boxes and can easily be adapted for use with many-to-many relationships.

Custom User Permissions: Part 1

When developing a full scale database application for Microsoft Access, one of the hurdles you're bound to run into sooner or later is the need for user permissions.  Managing who can see which forms, edit which records, run which reports, etc can seem like a daunting task for developers.  This series is focused on provided the knowledge and resources necessary in preparation for developing a user permissions management solution in your own database applications.

Function to Close All Forms

The CloseAllForms Function article posted in the UA Wiki  is a handy tool to close all active forms opened with the DoCmd.Open method.

The example code provided in the article includes optional arguments for excluding selected forms from being closed which is an added flexibility bonus.

Lebans: An excellent developer's resource ...

Looking for functional examples of advanced access development techniques?

Referencing Access Objects in a Query or Control



Referencing data in objects (tables, forms, queries, reports) is a basic skill in the Microsoft Access developer's toolkit, but what if you need to reference the objects themselves as part of a custom administrative interface (for example)?

Guide to Closing Forms with VBA

Because it may seem like a mundane task to many, it can be easy to overlook a few opportunities for improving our applications' overall performance with something as simple as closing a form.  AccessInsider explores one such opportunity by providing an example for utilizing a public function call to close forms in order to reduce the amount of code required to load each time a form is launched.

While any actual performance benefit will likely be undetectable using this particular example, it still provides an adequate demonstration of how a developer can streamline an application's code for repetitive procedures to optimize performance.

The common way closing a Microsoft Access for using VBA is by utilizing the DoCmd.Close method.

DoCmd.Close(ObjectType, ObjectName, Save)

Parameters
NameRequired/OptionalData TypeDescription
ObjectTypeOptionalAcObjectTypeAcObjectType constant that represents the type of object to close.
ObjectNameOptionalVariantA string expression that's the valid name of an object of the type selected by the objecttype argument.
SaveOptionalAcCloseSaveAcCloseSave constant tha specifies whether or not to save changes to the object. The default value isacSavePrompt.
Table Source: MSDN Office 2007: Access Developer's Reference

Example 1:

Private Sub cmdClose_Click()
     DoCmd.Close
End Sub

Result:

Closes the active window.

Example 2:

Private Sub cmdClose_Click()
     DoCmd.Close , , acSaveYes
End Sub

Result:

Closes and saves active window object.

Note: Notice that even though we didn't include the object type or object name parameters, we still had to include commas for those parameters when using the save parameter.  This can be avoided by identifying the parameters used as demonstrated below:

Private Sub cmdClose_Click()


    DoCmd.Close Save:=acSaveYes
   
End Sub

Tip: Naming the parameters in your code, as opposed to just using commas, will also make it more readable for other users/developers.

Example 3: Close a specified form.

Private Sub cmdCloseFunction_Click()


     DoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name


End Sub

Tip: Use quotation marks ("") around the form name for the ObjectName parameter when closing other forms.

Example 4: Closing a specified form using a public function call.

 Module: modPublicFunctions

Public Function CloseForm(FormName As String)
    
'// Author:     Jonathon Carrell
'// Purpose:    Public function to close forms.
'// History:    7 Jan 2012  Function created.


'// Close form.
    DoCmd.Close ObjectType:=acForm, ObjectName:=FormName
    
End Function


Form: frmCloseExample

Private Sub cmdCloseFunction_Click()


'// Call CloseForm function from modPublicFunctions to close this form.
    CloseForm Me.Name
    
End Sub

A functional example database can be found at this link: DoCmd.Close Method, or on theAccessInsider Examples Page.

Comments have been included with the example code as to provide the readers with a better understanding of the methods used.

Open Applications using Shell Method


In this post, we will go over one of the common methods for launching external programs from within Microsoft Access by utilizing the shell method in VBA.  A couple of other features also demonstrated in the example found at the end of this post are setting the external application as a child window within access and giving the shelled program a custom window caption by using API calls.

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More