使用 IsLoaded 屬性可以確定當(dāng)前是否加載了 AccessObject。Boolean 型,只讀。
expression 必需。返回“應(yīng)用于”列表中的一個(gè)對(duì)象的表達(dá)式。
IsLoaded 屬性使用以下設(shè)置:
設(shè)置 |
Visual Basic |
說(shuō)明 |
是 |
True |
加載了指定的 AccessObject。 |
否 |
False |
未加載指定的 AccessObject。 |
注釋 IsLoaded 屬性僅在使用 Visual Basic 時(shí)才可用,并且是只讀屬性。
該過(guò)程說(shuō)明了如何用 VBA 代碼將文本添加到數(shù)據(jù)訪問(wèn)頁(yè)中。以下信息提供了在過(guò)程中使用的參數(shù):
strPageName |
已有數(shù)據(jù)訪問(wèn)頁(yè)的名稱。 |
strID |
包含要使用文本的標(biāo)記的 ID 屬性。 |
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
End Function