使用 Document 屬性可以訪問(wèn) HTML 頁(yè)的 Microsoft Internet Explorer 動(dòng)態(tài) HTML Document 對(duì)象。
expression.Document
expression 必需。返回“應(yīng)用于”列表中的一個(gè)對(duì)象的表達(dá)式。
此屬性僅在使用 Visual Basic 時(shí)才可用。
有關(guān) DHTML 和 Document 對(duì)象模型的詳細(xì)信息,請(qǐng)參閱以下主題:
DHTML 教程
Document 對(duì)象模型
Document 對(duì)象引用
本過(guò)程說(shuō)明了如何用 VBA 代碼將文本添加到數(shù)據(jù)訪問(wèn)頁(yè)中。以下信息在過(guò)程的參數(shù)中提供:
strPageName |
已有的數(shù)據(jù)訪問(wèn)頁(yè)的名稱(chēng)。 |
strID |
包含要使用文本的標(biāo)記的 ID 屬性(參數(shù))。 |
strText |
要插入的文本。 |
blnReplace |
是否替換標(biāo)記中的已有文本。 |
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