CreateDataAccessPage Method Example

The following code fragment illustrates how you could create a new data access page, work with the HTML in the page, and then create a link to the page and permanently save it to disk. The procedure also illustrates one way to use an error trap to handle files that already exist:

Function CreateDAP(strFileName As String) As Boolean
    Dim dapNewPage As DataAccessPage
    
    Const DAP_EXISTS As Long = 2023
    
    On Error GoTo CreateDAP_Err
    ' Create the new page.
    Set dapNewPage = Application.CreateDataAccessPage(strFileName, _
        True)
    ' Use the Document property to return the Internet Explorer 5.0
    ' document object, and then use the Internet Explorer objects to
    ' work with the HTML in the page.
    
    With dapNewPage.Document
        .All("HeadingText").innerText = "This page was created " _
            & "programmatically!"
        .All("HeadingText").Style.display = ""
        .All("BeforeBodyText").innerText = "When you work " _
            & "with the HTML in a data access page, you " _
            & "must use the document property of the Page " _
            & "to get to the HTML. "
            .All("BeforeBodyText").Style.display = ""
    End With

    ' Close the page and save all changes.
    DoCmd.Close acDataAccessPage, dapNewPage.Name, acSaveYes
    CreateDAP = True
CreateDAP_End:
    Exit Function
CreateDAP_Err:
    If Err = DAP_EXISTS Then
        ' The file specified in strFileName already exists,
        ' so replace it with this new page.
        If MsgBox("'" & strFileName & " already exists. Do you " _
            & "want to replace it with a new, blank page?", vbYesNo, _
            "Replace existing page?") = vbYes Then
            Set dapNewPage = Application.CreateDataAccessPage(strFileName, False)
            Resume Next
        Else
            CreateDAP = False
            Resume CreateDAP_End
        End If
    Else
        CreateDAP = False
        Resume CreateDAP_End
    End If
End Function

The following example fragment illustrates how the CreateDataAccessPage method can be used to create multiple links to a single page on disk.

Sub Foo()
    Dim dapNewPage As DataAccessPage
    Set dapNewPage = _
        Application.CreateDataAccessPage("c:\footest.htm", True)
    DoCmd.Close acDataAccessPage, dapNewPage.Name, acSaveYes
    Set dapNewPage = _
        Application.CreateDataAccessPage("c:\footest.htm", False)
    DoCmd.Close acDataAccessPage, dapNewPage.Name, acSaveYes
End Sub