CurrentProject 物件 (Access)CurrentProject object (Access)

CurrentProject 物件參照目前 Microsoft Access 專案 (.adp) 或 Access 資料庫中的專案。The CurrentProject object refers to the project for the current Microsoft Access project (.adp) or Access database.

註解Remarks

CurrentProject物件有幾個集合包含目前資料庫中的特定**AccessObject** 物件。The CurrentProject object has several collections that contain specific AccessObject objects within the current database. 下表列出了每個集合的名稱,以及其中包含的物件類型。The following table lists the name of each collection and the types of objects it contains.


集合Collections 物件類型Object type
AllFormsAllForms 所有表單All forms
AllReportsAllReports 所有報表All reports
AllMacrosAllMacros 所有巨集All macros
AllModulesAllModules 所有模組All modules

注意

[!注意事項] 上表中的集合包含了資料庫中各方面的物件,不管它們是否開啟還是關閉。The collections in the preceding table contain all of the respective objects in the database regardless if they are opened or closed.

例如,代表在表單的 AccessObject 物件是 AllForms 集合,這是目前資料庫中的 AccessObject 物件的集合的成員。For example, an AccessObject object representing a form is a member of the AllForms collection, which is a collection of AccessObject objects within the current database. AllForms 集合內,將集合中的個別成員編製索引開頭為零。Within the AllForms collection, individual members of the collection are indexed beginning with zero. 您可以參閱下列的方式參照名稱或索引參照它集合內的表單在 AllForms 集合中的個別 AccessObject 物件。You can refer to an individual AccessObject object in the AllForms collection either by referring to the form by name, or by referring to its index within the collection. 如果您想要參照在AllForms集合中的特定物件,最好是因為可能會變更的項目集合索引依名稱參照至它。If you want to refer to a specific object in the AllForms collection, it's better to refer to it by name because an item's collection index may change. 如果物件名中包含空格,那麼必須先將名稱使用中括號 ([ ]) 括起來。If the object name includes a space, the name must be surrounded by brackets ([ ]).


語法Syntax 範例Example
AllForms!formnameAllForms!formname AllForms !訂購表單AllForms!OrderForm
AllForms![form name]AllForms![form name] AllForms![Order Form]AllForms![Order Form]
AllForms("formname")AllForms("formname") AllForms("OrderForm")AllForms("OrderForm")
AllForms(index)AllForms(index) AllForms(0)AllForms(0)

範例Example

下列範例列印CurrentProject物件的某些目前屬性設定,然後設定 [若要顯示在應用程式中的隱藏的物件] 選項。The following example prints some current property settings of the CurrentProject object, and then sets an option to display hidden objects within the application.

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

下一個範例示範如何使用 Automation 從另一個 Microsoft Office 應用程式使用CurrentProject物件。The next example shows how to use the CurrentProject object by using Automation from another Microsoft Office application. 首先,從另一個應用程式,建立 Microsoft Access 參照選擇 [模組] 視窗中 [工具] 功能表上的 [參考資料First, from the other application, create a reference to Microsoft Access by choosing References on the Tools menu in the Module window. 選取核取方塊旁的 [ Microsoft Access 物件程式庫中,然後在該應用程式內的 Visual Basic 模組中輸入下列程式碼並呼叫GetAccessData程序。Select the check box next to Microsoft Access Object Library, and then enter the following code in a Visual Basic module within that application and call the GetAccessData procedure.

此範例會將資料庫名稱和報表傳遞至建立Application類別的新執行個體,開啟資料庫,並驗證指定的報表存在使用CurrentProject物件和AllReports的程序集合。The example passes a database name and report name to a procedure that creates a new instance of the Application class, opens the database, and verifies that the specified report exists by using the CurrentProject object and AllReports collection.

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

方法Methods

屬性Properties

請參閱See also

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.