Access データベースのスタートアップ オプションを適用または無効にする方法

この記事は、Microsoft Access プロジェクト (.adp) にのみ適用されます。

中程度: 基本的なマクロ、コーディング、相互運用性のスキルが必要です。

概要

この記事では、スタートアップ オプションをバイパスできる Shift キーの機能を無効にする方法について説明します。 この記事では、Microsoft Access データベース プロジェクトでスタートアップ オプションを適用する方法についても説明します。

詳細

Access ファイルに対して定義されているスタートアップ オプションによって、ファイルの外観と、ファイルを開いたときにのファイルの動作が決まります。 スタートアップ オプションは、スタートアップ ユーザー インターフェイスを使用するか、AutoExec マクロを使用して設定できます。

Access データベース プロジェクトに設定されているスタートアップ オプションをバイパスするには、Shift キーを押しながら Access データベース プロジェクトを開きます。

または、Access データベース プロジェクトに設定されているスタートアップ オプションを適用するには、スタートアップ オプションをバイパスできる Shift キーの機能を無効にします。 これを行うには、AllowBypassKey プロパティを False に設定します。

AllowBypassKey プロパティを False に設定するには、次の手順に従います。

Access プロジェクトの手順 (.adp)

  1. Access を開始します。

  2. Access データベース プロジェクトを開きます。

  3. Alt キーを押しながら F11 キーを押して Visual Basic エディターを開きます。

  4. Visual Basic エディターで、[表示] メニューの [イミディエイト ウィンドウ] をクリックします。

  5. 次のコードを入力するか、[イミディエイト] ウィンドウに次のコードを貼り付けて、Enter キーを押します。

    CurrentProject.Properties.Add "AllowBypassKey", False
    
  6. Visual Basic エディターを閉じ、Access データベース プロジェクトを閉じます。

  7. Access データベース プロジェクトを開きます。 Access データベース プロジェクトを開いている間に Shift キーを押しながら Access データベース プロジェクトに設定されているスタートアップ オプションをバイパスしてみてください。

    スタートアップ オプションをバイパスできる Shift キーの機能は無効になっています。 Shift キーを押しながらスタートアップ オプションをバイパスしますが、スタートアップ オプションが実行されます。 スタートアップ オプションをバイパスすることはできません。

Access データベースの手順 (.mdb または .accdb)

  1. Access を開始します。

  2. 新しいモジュールを作成し、次の 2 つの関数を追加します。

    Function ap_DisableShift()
    'This function disable the shift at startup. This action causes
    'the Autoexec macro and Startup properties to always be executed.
    
    On Error GoTo errDisableShift
    
    Dim db As DAO.Database
    Dim prop as DAO.Property
    Const conPropNotFound = 3270
    
    Set db = CurrentDb()
    
    'This next line disables the shift key on startup.
    db.Properties("AllowByPassKey") = False
    
    'The function is successful.
    Exit Function
    
    errDisableShift:
    'The first part of this error routine creates the "AllowByPassKey
    'property if it does not exist.
    If Err = conPropNotFound Then
    Set prop = db.CreateProperty("AllowByPassKey", _
    dbBoolean, False)
    db.Properties.Append prop
    Resume Next
    Else
    MsgBox "Function 'ap_DisableShift' did not complete successfully."
    Exit Function
    End If
    
    End Function
    
    Function ap_EnableShift()
    'This function enables the SHIFT key at startup. This action causes
    'the Autoexec macro and the Startup properties to be bypassed
    'if the user holds down the SHIFT key when the user opens the database.
    
    On Error GoTo errEnableShift
    
    Dim db as DAO.Database
    Dim prop as DAO.Property
    Const conPropNotFound = 3270
    
    Set db = CurrentDb()
    
    'This next line of code disables the SHIFT key on startup.
    db.Properties("AllowByPassKey") = True
    
    'function successful
    Exit Function
    
    errEnableShift:
    'The first part of this error routine creates the "AllowByPassKey
    'property if it does not exist.
    If Err = conPropNotFound Then
    Set prop = db.CreateProperty("AllowByPassKey", _
    dbBoolean, True)
    db.Properties.Append prop
    Resume Next
    Else
    MsgBox "Function 'ap_DisableShift' did not complete successfully."
    Exit Function
    End If
    
    End Function
    
  3. Visual Basic エディターで、[表示] メニューの [イミディエイト ウィンドウ] をクリックします。

  4. Shift キーを無効にする場合は、[ イミディエイト ] ウィンドウに「ap_DisableShift」と入力し、Enter キーを押します。 シフト キーを有効にする場合は、[ イミディエイト ] ウィンドウに「ap_EnableShift」と入力し、Enter キーを押します。