Document 属性

       

使用 Document 属性可以访问 HTML 页的 Microsoft Internet Explorer 动态 HTML Document 对象

expression.Document

expression   必需。返回“Applies To”列表中的一个对象的表达式。

说明

此属性仅在使用 Visual Basic 时才可用。

有关 DHTML 和 Document 对象模型的详细信息,请参阅以下主题:

DHTML 教程

Document 对象模型

Document 对象引用

示例

本过程说明了如何用 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