Access データベースでスタートアップ オプションを適用または無効にする方法
この記事は、Microsoft Access プロジェクト (.adp) にのみ適用されます。
中程度: 基本的なマクロ、コーディング、相互運用性のスキルが必要です。
概要
この記事では、Shift キーの機能を無効にして、スタートアップ オプションをバイパスできるようにする方法について説明します。 この記事では、Microsoft Access データベース プロジェクトでスタートアップ オプションを適用する方法についても説明します。
詳細情報
Access ファイルに対して定義されているスタートアップ オプションは、ファイルの外観と、ファイルを開いたときのファイルの動作を決定します。 スタートアップ ユーザー インターフェイスを使用するか、AutoExec マクロを使用して、スタートアップ オプションを設定できます。
Access データベース プロジェクトに設定されているスタートアップ オプションをバイパスするには、Access データベース プロジェクトを開いている間、Shift キーを押したままにします。
または、Access データベース プロジェクトに設定されているスタートアップ オプションを適用するには、Shift キーの機能を無効にして、スタートアップ オプションをバイパスできます。 これを行うには、AllowBypassKey プロパティを False に設定します。
AllowBypassKey プロパティを False に設定するには、次の手順に従います。
Access プロジェクト (.adp) の手順
アクセスを開始します。
Access データベース プロジェクトを開きます。
Alt キーを押しながら F11 キーを押して Visual Basic エディターを開きます。
Visual Basic エディターで、[表示] メニューの [イミディエイト ウィンドウ] をクリックします。
次のコードを入力するか、[イミディエイト] ウィンドウに次のコードを貼り付けてから、Enter キーを押します。
CurrentProject.Properties.Add "AllowBypassKey", False
Visual Basic エディターを閉じてから、Access データベース プロジェクトを閉じます。
Access データベース プロジェクトを開きます。 Access データベース プロジェクトを開いている間、Shift キーを押しながら Access データベース プロジェクトに設定されているスタートアップ オプションをバイパスしてみてください。
スタートアップ オプションをバイパスできるようにする Shift キーの機能は無効になっています。 Shift キーを押しながらスタートアップ オプションをバイパスしますが、スタートアップ オプションが実行されます。 スタートアップ オプションをバイパスすることはできません。
Access データベース (.mdb または .accdb) の手順
アクセスを開始します。
新しいモジュールを作成し、次の 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
Visual Basic エディターで、[表示] メニューの [イミディエイト ウィンドウ] をクリックします。
Shift キーを無効にする場合は、[ イミディエイト ] ウィンドウに「ap_DisableShift」と入力し、Enter キーを押します。 Shift キーを有効にする場合は、[ イミディエイト ] ウィンドウに「ap_EnableShift」と入力し、Enter キーを押します。