Creating a Pop-up Data Access Page

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

 

Meyyammai Subramanian
Microsoft Corporation

April 2001

Applies to:
   Microsoft® Access 2002

Summary: This article explains how to create a data access page that pops up in a separate window when the user clicks a record or activates a PivotTable list. (6 printed pages)

Contents

Show a Pop-up Page When the User Clicks a Record on the Main Page Show a Pop-up Page When the User Double-clicks a Cell Inside a PivotTable List on the Main Page

Show a Pop-up Page When the User Clicks a Record on the Main Page

When the user clicks a record, you can display another data access page on top of the main page that shows additional details or allows the user to edit the current record.

The following illustration shows the Edit Products page in a modal window that enables the user to edit the current record.

  Products page is the main page.

Aa139966.odc_creatingapopuppage3(en-us,office.10).gif  Edit Products page pops up when the user clicks a record on the main page.

Figure 1. A data access page in modal window

When the user clicks Save, the pop-up page closes and the main page refreshes to show the latest data.

Show a Pop-up Page When the User Double-clicks a Cell Inside a PivotTable List on the Main Page

If the main page contains a PivotTable list, you can display a pop-up page when the user clicks a cell within the PivotTable list.

The following illustration shows the Edit Products page, which pops up when the user double-clicks a Product ID displayed in the PivotTable list.

Figure 2. A data access page in modal window

Create a Pop-up Page

  1. Open a new page in Design view and add the desired controls, including the Save and Cancel buttons.

  2. In the OnClick event of the Cancel button, add the following lines of code:

    <SCRIPT language=vbscript event=onclick for=btnCancel>
    <!--
    MSODSC.DataPages(0).Undo
    ' Setting this property allows you to pass information back to the 
    ' original page.
    
    ' In this case, the property is used to determine if the page should be 
    ' refreshed.
    window.returnvalue = "false"
    window.close
    -->
    </SCRIPT>
    
  3. In the OnClick event of the Save button, add the following lines of code:

    <SCRIPT language=vbscript event=onclick for=btnSave>
    <!--
    MSODSC.DataPages(0).Save
    window.returnvalue = "true"
    window.close
    -->
    </SCRIPT>
    
  4. Before the closing <BODY> tag, add code to set the server-side filter based on the record that was clicked in the main page.

    <SCRIPT language=vbscript>
    <!--
    dim ProductID
    
    ProductID = window.dialogarguments
    MSODSC.RecordsetDefs("Products").serverfilter = "ProductID = " & _
                                                        ProductID
    -->
    </SCRIPT>
    

Create a Page that Displays the Pop-up Page When the User Clicks a Record

  1. Open a new page in Design view and add the desired controls.

  2. In the OnClick event of the header section, add code to display the pop-up page and refresh the page after the pop-up page closes.

    The following is a sample OnClick event for the Products header section.

    <SCRIPT language=vbscript event=onclick for=HeaderProducts>
    <!--
    
    If document.location.protocol = "accdp:" Then
        bInAccess = TRUE
        msgbox "This feature isn't supported inside Access. Try again in 
                                                             the browser."
    Else
        bInAccess = FALSE
    
        dim fResync
        dim dlgFormat   
        dim iProductID
    
        ' Sets how the editable dialog will be displayed.
        dlgFormat = "dialogHeight: 252; dialogWidth: 244; center: yes; _
                                               resizable: no; status: no;" 
    
        ' Retrieves the ProductID of the clicked-on product so the dialog 
        ' can be filtered to it
        iProductID = MSODSC.GetContainingSection(me).DataPage _ 
                                       .Recordset.Fields("ProductID").value
    
        fResync = showModalDialog("Popup_Child.htm",iProductID, _
                 "dialogHeight: 240px; dialogWidth: 406px; center: yes; _
                 resizable: no; status: no;")
    
        ' The pop-up page will set the fResync value equal to True if the 
        ' data changed. If it is True, the page will be refreshed to show 
        ' the updated values. This is a generic mechanism for passing 
        ' values back to the original page.
    
        If (fResync = "true") Then 
        ' Call RefreshJetCache only when working against Access databases.
         ' This isn't required for SQL Server pages.
        MSODSC.RefreshJetCache
        MSODSC.GetContainingSection(me).DataPage.Recordset.Resync 1 ,2
        End If
    End If
    -->
    </SCRIPT> 
    

Create a Page that Displays the Pop-up Page When the User Double-clicks a Cell Inside a PivotTable List

  1. Open a new page in Design view and add the desired controls, including the PivotTable list.

  2. In the DblClick event of the PivotTable list, add code to display the pop-up page, and refresh the page after the pop-up page closes.

    The following is a sample DblClick event for the PivotTable list.

    <SCRIPT language=vbscript event=dblClick for=pivottable0>
    <!--
    dim fResync
    dim dlgFormat   
    dim strURL
    dim strProductID
    dim iRetVal
    dim bInAccess
    
    strURL = "Popup_Child.htm"
    if document.all.PivotTable0.object.selection.bottomright _         
                                        .field.baseName="ProductID" Then
        If document.location.protocol = "accdp:" Then
            bInAccess = TRUE
            msgbox "This feature isn't supported inside Access. Choose File 
                                                       | Web Page Preview."
        Else
            bInAccess = FALSE
            ' Retrieves the ProductID of the clicked-on product so the 
            ' dialog can be filtered to it.
            strProductID = document.all.PivotTable0 _
                                         .object.selection.bottomright.text
            ' Create the filter string cookie that the next page will read.
            ' The string sets how the editable dialog will be displayed.
            dlgFormat = "dialogHeight: 252; dialogWidth: 244; center: _
                                       yes; resizable: no; status: no;"
    
              fResync = showModalDialog(strURL,strProductID, "dialogHeight: _
                          240px; dialogWidth: 406px; center: yes; 
                          resizable: no; status: no;")
    
            ' The pop-up page will set the fResync value equal to True if 
            ' the data changed. If it is True, the page should be refreshed 
            ' to show the updated values.
    
            If (fResync = "true") Then 
                  window.location.reload()
              End If
    
        End If
    End If
    
    -->
    </SCRIPT>