Table of contents
XML
TOC
Collapse the table of content
Expand the table of content

Create a Database Template Programmatically

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

The SaveAsTemplate method enables you to convert an existing Access database file to a database template (.accdt) format file that can be featured on the Getting Started with Microsoft Office Access page.

Syntax

expression. SaveAsTemplate( TemplateLocation, TemplateName, PreviewImage, Description, Category, Keywords, Identifier, Reserved )

expression A variable that represents a TemplateCreator object.

The following table describes the arguments of the SaveAsTemplate method.

NameRequired/OptionalData TypeDescription
TemplateLocationRequiredStringThe full path and file name of the database template to create.For the template to appear on the Getting Started with Microsoft Office Access page, it must be saved to Microsoft\Templates subfolder of the user's Application Data folder. In Windows XP, the default location of the Application Data folder is C:\Documents and Settings\ User Name \Application Data, where User Name is the name of the user who is currently logged on.In Windows Vista, the default location of the Application Data folder is C:\Users\ User Name \AppData\Roaming, where User Name is the name of the user who is currently logged on.You can use the Environ function to determine the current location of the user's Application Data folder. The following code illustrates how to do this. strTemplateLocation = Environ("AppData") &; "\Microsoft\Templates\"
TemplateNameOptionalStringThe name of the database that is created when the user opens the template.
PreviewImageOptionalStringAn image file to be used as a preview for the database template on the Getting Started with Microsoft Office Access page.
DescriptionOptionalStringA description to be displayed when the user selects the database template in the Getting Started with Microsoft Office Access page.
CategoryOptionalStringThe Template Category under which the database template will appear on the Getting Started with Microsoft Office Access page.
KeywordsOptionalStringKeywords to be added to the template's file properties.
IdentifierOptionalString
ReservedOptionalString

Usage

You must instantiate the TemplateCreator object before you call the SaveAsTemplate method. Instantiating the TemplateCreator object requires a different technique from instantiating the built-in objects in Access. To instantiate the TemplateCreator object, you must use the COMAddins collection.

The following code illustrates how to instantiate the AccessDeveloperExtensions object through the COMAddins collection.

Set objTemplate = Application.COMAddIns("AccessAddIn.ADE").Object.TemplateObject 

The following example creates a new template named Asset Tracker and assigns it to the Departmental data category on the Getting Started with Microsoft Office Access page.

    Dim objTemplate As TemplateCreator 
    Dim strTemplateLocation As String 

    ' The database template must be saved to this location to appear on the 
    ' Getting Started with Microsoft Office Access page. 
    strTemplateLocation = Environ("AppData") &; "\Microsoft\Templates\" 

    ' Instantiate a TemplateObject object. 
    Set objTemplate = Application.COMAddIns("AccessAddIn.ADE").Object.TemplateObject 

    ' Create the database template.     
    objTemplate.SaveAsTemplate TemplateLocation:=strTemplateLocation &; "AssetTracker.accdt", _ 
                               TemplateName:="Asset Tracker", _ 
                               Category:="Departmental Data"

You must set a reference to the Access Developer Extensions type library in order to use the SaveAsTemplate method. To do this, follow these steps:

  1. On the Tools menu, click References.

  2. Select the Microsoft Office Access Developer Extensions Type Library 1.0 check box, and then click OK.

© 2018 Microsoft