使用 IsLoaded 属性可以确定当前是否加载了 AccessObject。Boolean 型,只读。
expression.IsLoaded
expression 必需。返回“Applies To”列表中的一个对象的表达式。
IsLoaded 属性使用以下设置:
| 设置 | Visual Basic | 说明 | 
|---|---|---|
| 是 | True | 加载了指定的 AccessObject。 | 
| 否 | False | 未加载指定的 AccessObject。 | 
该过程说明了如何用 VBA 代码将文本添加到数据访问页中。以下信息提供了在过程中使用的参数:
| strPageName | 已有数据访问页的名称。 | 
| strID | 包含要使用文本的标记的 ID 属性。 | 
| strText | 要插入的文本。 | 
| blnReplace | 是否替换标记中的已有文本。 | 
Function DAPInsertText(strPageName As String, _
    strID As Variant, strText As String, _
    Optional blnReplace As Boolean = True) As Boolean
    Dim blnWasLoaded As Boolean
    On Error GoTo DAPInsertText_Err
    ' Determine if the page exists and whether it is
    ' currently open. If not open then open it in
    ' design view.
    If DAPExists(strPageName) = True Then
        If CurrentProject.AllDataAccessPages(strPageName) _
            .IsLoaded = False Then
            blnWasLoaded = False
            With DoCmd
                .Echo False
                .OpenDataAccessPage strPageName, _
                    acDataAccessPageDesign
            End With
        Else
            blnWasLoaded = True
        End If
    Else
        DAPInsertText = False
        Exit Function
    End If
    ' Add the new text to the specified tag.
    With DataAccessPages(strPageName).Document
        If blnReplace = True Then
            .All(strID).innerText = strText
        Else
            .All(strID).innerText = .All(strID).innerText & strText
        End If
        ' Make sure the text is visible.
        With .All(strID).Style
            If .display = "none" Then .display = ""
        End With
    End With
    ' Clean up after yourself.
    With DoCmd
        If blnWasLoaded = True Then
        .Save
    Else
        .Close acDataAccessPage, strPageName, acSaveYes
        End If
    End With
    DAPInsertText = True
DAPInsertText_End:
    DoCmd.Echo True
    Exit Function
DAPInsertText_Err:
    MsgBox "Error #" & Err.Number & ": " & Err.Description
    DAPInsertText = False
    Resume DAPInsertText_End
End Function