CurrentProject 對象

此頁沒有內(nèi)容條目
內(nèi)容

expandtri全部顯示

Application

parchildCurrentProject

spaceparchild多個(gè)對象

CurrentProject 對象引用當(dāng)前 Microsoft Access 項(xiàng)目(.adp)或 Access 數(shù)據(jù)庫(.mdb)的項(xiàng)目。

使用 CurrentProject 對象

CurrentProject 對象有好幾個(gè)集合,每個(gè)集合都包含當(dāng)前數(shù)據(jù)庫中的特定 AccessObject 對象。下表列出了每個(gè)集合的名稱及其所含對象的類型。

集合

對象類型

AllForms

所有窗體

AllReports

所有報(bào)表

AllMacros

所有宏

AllModules

所有模塊

AllDataAccessPages

所有數(shù)據(jù)訪問頁

 

注釋  上表中的集合包含了數(shù)據(jù)庫中各方面的對象,不管它們是打開還是關(guān)閉。

例如,代表窗體的 AccessObject 對象是 AllForms 集合的一個(gè)成員,而 AllForms 集合是當(dāng)前數(shù)據(jù)庫中 AccessObject 對象的一個(gè)集合。在 AllForms 集合中,集合的每個(gè)成員從零開始編制索引。通過按名稱引用窗體或引用其在集合中的索引,可以引用 AllForms 集合中的單個(gè) AccessObject 對象。如果想引用 AllForms 集合中的特定對象,最好按名稱引用它,因?yàn)轫?xiàng)的集合索引可能會變動。如果對象名中包含空格,則必須將名稱用方括號([ ])括起來。

語法

示例

AllForms!formname

AllForms!OrderForm

AllForms![form name]

AllForms![Order Form]

AllForms("formname")

AllForms("OrderForm")

AllForms(index)

AllForms(0)

下面的示例打印 CurrentProject 對象的一些當(dāng)前屬性設(shè)置,然后設(shè)置選項(xiàng)以顯示應(yīng)用程序中的隱藏對象:

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

下一個(gè)示例顯示如何使用“自動化”從另一個(gè) Microsoft Office 應(yīng)用程序中使用 CurrentProject 對象。首先,從另一個(gè)應(yīng)用程序中創(chuàng)建對 Microsoft Access 的引用,方法是:在“模塊”窗口中單擊“工具”菜單上的“引用”。選中 Microsoft Access Object Library 旁的復(fù)選框。然后在該應(yīng)用程序的 Visual Basic 模塊中輸入下列代碼,并調(diào)用 GetAccessData 過程。

該示例將一個(gè)數(shù)據(jù)庫名和報(bào)表名傳遞給一個(gè)創(chuàng)建 Application 類的新實(shí)例的過程,打開數(shù)據(jù)庫,并使用 CurrentProject 對象和 AllReports 集合驗(yàn)證指定的報(bào)表是否存在。

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

    appAccess.CurrentProject.AllReports(strReportName)

    MsgBox "Report " & strReportName & _

        " verified within Northwind database."

    appAccess.CloseCurrentDatabase

    Set appAccess = Nothing

Exit Sub

ErrorHandler:

    MsgBox "Report " & strReportName & _

        " does not exist within Northwind database."

    appAccess.CloseCurrentDatabase

    Set appAccess = Nothing

End Sub