Export (0) Print
Expand All
Expand Minimize

Setting Startup Options Programmatically in Access 2000

Office 2000
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
 

Acey James Bunch
Microsoft Corporation

March 2000

Applies To: Microsoft® Access 2000

Summary: This article covers setting the startup options for Access in programming code. It includes discussion, sample code, and detailed tables of all appropriate options. It highlights those options that were documented incorrectly and points out some undocumented options. (9 printed pages)

Contents

What Are Startup Options?
Setting Options in Programming Code
   
Setting Startup Options for .mdb Databases
   
Setting Startup Options for .adp Databases
Startup Options Summary
   
Standard Options
   
Advanced Options
   
Extra Options
Additional Resources

What Are Startup Options?

As with previous versions of Microsoft® Access, Access 2000 allows you to set many startup options that affect various aspects of the Access environment for individual database applications. This article discusses the many different options that you can use and the different ways in which you can use them.

Startup options are those options that affect the behavior and appearance of an individual Access application when it is first launched or opened. Because these settings stay with the database, they are stored in the database Properties collection, and they will only apply to the database in which they are set. The startup options that are available from the user interface can be found by clicking the Tools menu, then selecting Startup.

Aa140020.acstartupoptions1(en-us,office.10).gif

Figure 1. The Startup Options dialog box

Note that the Advanced button (upper right corner) on the startup options dialog box expands the dialog to include the Use Access Special Keys option (lower left). The screen shot above shows the fully expanded startup options dialog box.

Setting Options in Programming Code

Although the startup options may be set in the Access user interface, you can also set them by using programming code. In general, there are three types of option values that you can set: true/false, alphanumeric, and predefined.

  • True/false values are those options that are turned on or off with a check box, and the value returned or set is either True (-1) or False (0).
  • Alphanumeric values are those options that can be set by entering a string or numeric value, and the values returned or set are strings, just as they appear in the startup options dialog box.
  • Predefined values are those options that can be chosen from a list box, combo box, or option group, and the values returned or set correspond to the option's position in a list or option group, with the indexing of those values beginning with zero.

As mentioned before, startup options affect how an application appears when it is first opened. How you manipulate the startup options programmatically depends on the type of database you are using. For applications built using the Jet database engine (.mdb files), the startup properties can be accessed through the Properties collection of the CurrentDB object. But for applications built by using Access projects (.adp files) with Microsoft Data Engine (MSDE) or Microsoft SQL Server™ as the database, the startup properties are accessed through the Properties collection of the CurrentProject object.

Another aspect of startup options is that they don't initially exist for new databases, not until you make a change to them in the user interface or in programming code. This means that when working with the startup options in code, you should always first check that the property exists. One way to do this is to trap for the "Property Not Found" error. The following sections show how to use the startup option properties with both the Jet database engine (.mdb file) and MSDE or SQL Server (.adp file).

Setting Startup Options for .mdb Databases

To set the startup options for applications built by using the Jet database engine (.mdb), you can use the Properties collection of the current database (CurrentDB) object, which is a method of the Application object. It does not matter whether you are using Data Access Objects (DAO) or ActiveX® Data Objects (ADO), accessing the startup options is the same for both.

If you try to retrieve or set a startup property that does not yet exist, the Jet/DAO error number 3270, "Property not found," will be generated. In your code you should trap for this error. If it occurs, you know that you must create and append the property to the Properties collection. The following code demonstrates how to trap for the error and then set the Application Title property. Notice the use of the generic Object variables to hold the CurrentDB and Property values. This is because internally, Access is using the DAO 3.6 Database and Property objects to work with startup properties, but you can't explicitly use those objects without setting a reference to the DAO 3.6 Object Library. The reason for using the generic object variables is so that we don't assume a particular reference to either DAO or ADO, either data access method will work with this sample code.

Public Sub SetMDBAppTitle()
   Dim dbs As Object
   Dim prp As Object
   Dim strTitle As String

   Const PROPERTY_NOT_FOUND As Integer = 3270
   Const TEXT_TYPE As Integer = 10
   ' Equivalent to DAO dbText data type.
   Const BOOL_TYPE As Integer = 1
   ' Equivalent to DAO dbBoolean data type.
   Const LONG_TYPE As Integer = 4
   ' Equivalent to DAO dbLong data type.

   On Error GoTo ErrorHandler

   Set dbs = Application.CurrentDb
   strTitle = "Setting *.MDB Startup Options"

   ' Try to set the property. If it fails, the property does not exist.
   dbs.Properties("AppTitle") = strTitle

   ' Refresh the title bar to reflect the change.
   Application.RefreshTitleBar

ExitLine:
   dbs.Close
   Set dbs = Nothing
   Set prp = Nothing
   Exit Sub

ErrorHandler:
   If Err.Number = PROPERTY_NOT_FOUND Then
      ' Create the new property.
      Set prp = dbs.CreateProperty("AppTitle", TEXT_TYPE, strTitle)
      dbs.Properties.Append prp
      Resume Next
   Else
      Resume ExitLine
   End If

End Sub

To remove the startup property and return to the default value, use the Delete method of the Properties collection. If you try to delete a property that does not exist, the Jet/DAO error number 3265, "Item not found in this collection," will be generated. In your code you should trap for this error and if it occurs, simply exit the procedure. The following code demonstrates how to trap for the error and update the title bar if necessary.

Public Sub RemoveMDBAppTitle()
   Dim dbs As Object

   Const ITEM_NOT_IN_COLLECTION As Integer = 3265

On Error GoTo ErrorHandler

   Set dbs = Application.CurrentDb

   ' Remove the startup property.
   dbs.Properties.Delete ("AppTitle")

   'Refresh the title bar to reflect the change.
   Application.RefreshTitleBar

ExitLine:
   dbs.Close
   Set dbs = Nothing
   Exit Sub

ErrorHandler:
   If Err.Number = ITEM_NOT_IN_COLLECTION Then
      Resume ExitLine
   Else
      Resume Next
   End If

End Sub

Setting Startup Options for .adp Databases

To set the startup options for applications built by using Access projects (.adp) with either SQL Server or MSDE, you can use the Properties collection of the CurrentProject object, which is in turn a property of the Application object.

If you try to retrieve or set a startup property that does not yet exist, error number 2455, "…invalid reference to the property…," will be generated. In your code you should trap for this error. If it occurs, you know that you must add the property to the Properties collection. The following code demonstrates how to trap for the error and then set the Application Title property. Note that when you add the property to the Properties collection, you do not have to specify the data type of the property.

Public Sub SetADPAppTitle()
   Dim dbs As CurrentProject
   Dim prp As ADODB.Property
   Dim strTitle As String

   Const INVALID_PROPERTY_REFERENCE As Integer = 2455

On Error GoTo ErrorHandler

   Set dbs = Application.CurrentProject
   strTitle = "Setting *.ADP Startup Options"

   'Try to set the property, if it fails, the property does not exist.
   dbs.Properties("AppTitle") = strTitle

   'Refresh the title bar to reflect the change.
   Application.RefreshTitleBar
   
ExitLine:
   Set dbs = Nothing
   Set prp = Nothing
   Exit Sub

ErrorHandler:
   If Err.Number = INVALID_PROPERTY_REFERENCE Then
      ' Create the new property.
      dbs.Properties.Add "AppTitle", strTitle
      Resume Next
   Else
      Resume ExitLine
   End If

End Sub

To remove the startup property and return to the default value, use the Remove method of the Properties collection. If you try to remove a property that does not exist, error number 2455, "…invalid reference to the property…," will be generated. In your code you should trap for this error and if it occurs, simply exit the procedure. The following code demonstrates how to trap for the error and update the title bar if necessary.

Public Sub RemoveADPAppTitle()
   Dim dbs As CurrentProject

   Const INVALID_PROPERTY_REFERENCE As Integer = 2455

   On Error GoTo ErrorHandler

   Set dbs = Application.CurrentProject

   ' Remove the startup property.
   dbs.Properties.Remove "AppTitle"

   ' Refresh the title bar to reflect the change.
   Application.RefreshTitleBar

ExitLine:
   Set dbs = Nothing
   Exit Sub

ErrorHandler:
   If Err.Number = INVALID_PROPERTY_REFERENCE Then
      Resume ExitLine
   Else
      Resume Next
   End If

End Sub

For more information about setting startup options programmatically, type startup properties in the Office Assistant or on the Answer Wizard tab in the Visual Basic for Applications Help window, and then click Search.

Startup Options Summary

The following sections discuss all of the different options available from the Startup Options dialog box, and they also cover the values that you use can use to manipulate startup options in programming code. The name values are the exact names that you should use in code. In some cases, the effect of setting the startup options will not take place until the application is closed and then reopened.

Standard Options

The following options are equivalent to the standard startup options found in the Startup Options dialog box.

NameValueDescription
AppTitleStringThe title of an application, as displayed in the title bar.
AppIconStringThe file name and path of an application's icon.
StartupMenuBarStringSets the default menu bar for the application.
AllowFullMenusTrue/FalseDetermines if the built-in Access menu bars are displayed.
AllowShortcutMenusTrue/FalseDetermines if the built-in Access shortcut menus are displayed.
StartupFormStringSets the form or data page to show when the application is first opened.
StartupShowDBWindowTrue/FalseDetermines if the database window is displayed when the application is first opened.
StartupShowStatusBarTrue/FalseDetermines if the status bar is displayed.
StartupShortcutMenuBarStringSets the shortcut menu bar to be used in all forms and reports.
AllowBuiltInToolbarsTrue/FalseDetermines if the built-in Access toolbars are displayed.
AllowToolbarChangesTrue/FalseDetermined if toolbar changes can be made.

Advanced Option

The AllowSpecialKeys option (True/False value) determines if the use of special keys is permitted. It is equivalent to the advanced startup option found in the Startup Options dialog box.

Extra Options

The following options are not available from the Startup Options dialog box or any other Access user interface component, they are only available in programming code.

NameValuesDescription
AllowBypassKeyTrue/FalseDetermines if the SHIFT key can be used to bypass the application load process.
AllowBreakIntoCodeTrue/FalseDetermines if the CTRL+BREAK key combination can be used to stop code from running.
HijriCalendarTrue/FalseApplies only to Arabic countries; determines if the application uses Hijri or Gregorian dates.

Additional Resources

Microsoft Office 2000/Visual Basic Programmer's Guide. This comprehensive book covers Office programming with the Visual Basic for Applications programming language.

MSDN (http://msdn.microsoft.com/). This Web site always has the latest information for developing solutions with Microsoft platforms and languages.

Microsoft Office Developer (http://msdn.microsoft.com/office/default.asp). Look here for the latest information on developing applications with Microsoft Office.

Show:
© 2014 Microsoft