使用 IsLoaded 屬性可以確定當前是否加載了 AccessObject。Boolean 型,只讀。
expression 必需。返回“應用于”列表中的一個對象的表達式。
IsLoaded 屬性使用以下設置:
設置 |
Visual Basic |
說明 |
是 |
True |
加載了指定的 AccessObject。 |
否 |
False |
未加載指定的 AccessObject。 |
注釋 IsLoaded 屬性僅在使用 Visual Basic 時才可用,并且是只讀屬性。
該過程說明了如何用 VBA 代碼將文本添加到數(shù)據(jù)訪問頁中。以下信息提供了在過程中使用的參數(shù):
strPageName |
已有數(shù)據(jù)訪問頁的名稱。 |
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