CurrentProject オブジェクトは、Microsoft Office Access のカレント プロジェクト (.adp) またはデータベース に対するプロジェクトを参照します。
注釈
CurrentProject オブジェクトには、現在のデータベース内に特定の AccessObject オブジェクトを含むいくつかのコレクションがあります。 各コレクションの名前とそれに含まれるオブジェクトの種類は次のとおりです。
| コレクション | オブジェクトの種類 |
|---|---|
| AllForms | すべてのフォーム |
| AllReports | すべてのレポート |
| AllMacros | すべてのマクロ |
| AllModules | すべてのモジュール |
注:
[!メモ] 上の表に示したコレクションは、データベースの対応するオブジェクトを開いているまたは閉じているにかかわらずすべて含みます。
たとえば、フォームを示す AccessObject は、 AllForms コレクションのメンバーであり、このコレクションは、カレント データベース内の AccessObject オブジェクトのコレクションです。 AllForms コレクションでは、各メンバーにゼロから始まるインデックスが付けられています。 AllForms コレクション内の個々の AccessObject オブジェクトを参照するには、名前でフォームを参照するか、コレクション内のその索引を参照します。 AllForms コレクション内の特定のオブジェクトを参照する場合は、アイテムのコレクション インデックスが変更される可能性があるため、名前で参照することをお勧めします。 オブジェクト名にスペースが含まれる場合は、名前を角かっこ ([ ]) で囲む必要があります。
| 構文 | 例 |
|---|---|
| AllForms!formname | AllForms!受注フォーム |
| AllForms![form name] | AllForms![受注 フォーム] |
| AllForms("formname") | AllForms("受注フォーム") |
| AllForms(index) | AllForms(0) |
例
次の例では、 CurrentProject オブジェクトの現在のプロパティ設定の一部を印刷し、非表示のオブジェクトをアプリケーション内に表示するためのオプションを設定します。
Sub ApplicationInformation()
' Print name and type of current object.
Debug.Print Application.CurrentProject.FullName
Debug.Print Application.CurrentProject.ProjectType
' Set Hidden Objects option under Show on View Tab
'of the Options dialog box.
Application.SetOption "Show Hidden Objects", True
End Sub
次の例は、オートメーションを使用して CurrentProject オブジェクトを使用する方法を示しています。 まず、他のアプリケーションから、[モジュール] ウィンドウの [ツール] メニューの [参照] を選択して、Microsoft Access への参照を作成します。 Microsoft Access オブジェクト ライブラリの横にあるチェック ボックスをオンにし、そのアプリケーション内の Visual Basic モジュールに次のコードを入力して、GetAccessData プロシージャを呼び出します。
この例では、データベース名とレポート名を、Application クラスの新しいインスタンスを作成し、データベースを開き、CurrentProject オブジェクトと AllReports コレクションを使用して指定されたレポートが存在することを確認するプロシージャに渡します。
Sub GetAccessData()
' Declare object variable in declarations section of a module
Dim appAccess As Access.Application
Dim strDB As String
Dim strReportName As String
strDB = "C:\Program Files\Microsoft " _
& "Office\Office11\Samples\Northwind.mdb"
strReportName = InputBox("Enter name of report to be verified", _
"Report Verification")
VerifyAccessReport strDB, strReportName
End Sub
Sub VerifyAccessReport(strDB As String, _
strReportName As String)
' Return reference to Microsoft Access
' Application object.
Set appAccess = New Access.Application
' Open database in Microsoft Access.
appAccess.OpenCurrentDatabase strDB
' Verify report exists.
On Error Goto ErrorHandler
IsObject appAccess.CurrentProject.AllReports(strReportName)
MsgBox "Report " & strReportName & _
" verified within " & appAccess.CurrentProject.Name & " database."
appAccess.CloseCurrentDatabase
Set appAccess = Nothing
Exit Sub
ErrorHandler:
MsgBox "Report " & strReportName & _
" does not exist within " & appAccess.CurrentProject.Name & " database."
appAccess.CloseCurrentDatabase
Set appAccess = Nothing
End Sub
メソッド
プロパティ
- AccessConnection
- AllForms
- AllMacros
- AllModules
- AllReports
- アプリケーション
- BaseConnectionString
- Connection
- FileFormat
- FullName
- ImportExportSpecifications
- IsConnected
- IsTrusted
- IsWeb
- 名前
- Parent
- パス
- ProjectType
- プロパティ
- RemovePersonalInformation
- リソース
- WebSite
- IsSQLBackend
関連項目
サポートとフィードバック
Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。