ACC2002: Cannot Bind a Grouped Report That Was Saved as a Data Access Page to XML (287445)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q287445
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SYMPTOMS

When you bind a data access page that was saved from a grouped report to XML, only the lowest level group on the page is bound. Other groups on the page do not display data.

CAUSE

There are brackets ([]) in the names of page field objects on the page.

RESOLUTION

Remove the brackets from the page field objects on the page as follows:

CAUTION: Following the steps in this example will modify your data access page. You may want to back up the page and perform these steps on a copy of the page.
  1. Start Access 2002, and then open the database that contains your page.
  2. Click your data access page in the Database window, and then open it in Design view.
  3. On the View menu, click Data Outline to view the data model for the page.
  4. Right-click a page field that has brackets listed in the data outline, and then click Properties. The title on the Properties dialog box should read PageField: [FieldName]
  5. Remove the brackets from the Name property of the page field.
  6. Save the page, and then view it in Page view. All the fields on the page should be bound to XML.

If your page has many page fields that contain brackets around the name, you can use Visual Basic for Applications code to programmatically remove the brackets from the names. To do so, follow these steps.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
  1. Start Access 2002, and then open the database that contains your page.
  2. In the Database window, click Modules under Objects, and then click New.
  3. Type or paste the following code into the new module:
    Sub RemoveBrackets(strPageName As String)
        On Error GoTo RemoveBracketErrors
        
        Dim dap As DataAccessPage
        Dim gdf As Object   ' GroupingDef object
        Dim pgf As Object   ' PageField object
        Dim strNewName As String
        
        ' if the page is not open, open it in Design view
        If Not CurrentProject.AllDataAccessPages(strPageName).IsLoaded Then
            DoCmd.OpenDataAccessPage strPageName, acDataAccessPageDesign
        End If
        
        ' set the object variable
        Set dap = DataAccessPages(strPageName)
        
        ' iterate through grouping definitions on the page
        For Each gdf In dap.MSODSC.AllGroupingDefs
            ' loop through AllPageFields collection
            For Each pgf In gdf.PageFields
                ' find PageFields that contain brackets in the name
                If InStr(1, pgf.Name, "[") > 0 Then
                    ' remove the brackets and rename the PageField
                    strNewName = Mid(pgf.Name, 2, InStr(2, pgf.Name, "]") - 2)
                    pgf.Name = strNewName
                End If
            Next
        Next
        
        ' close and save the page
        DoCmd.Close acDataAccessPage, strPageName, acSaveYes
        
    RemoveBracketExit:
        ' cleanup
        Set pgf = Nothing
        Set gdf = Nothing
        Set dap = Nothing
        MsgBox "Page fields with brackets have been renamed"
        Exit Sub
        
    RemoveBracketErrors:
        Const CON_ERR_CANNOTFINDPAGE = 7874
        Const CON_ERR_CANNOTFINDOBJ = 2467
        
        If (Err = CON_ERR_CANNOTFINDPAGE Or Err = CON_ERR_CANNOTFINDOBJ) Then
            MsgBox "Cannot find the specified page: " & vbCrLf & vbCrLf & strPageName, vbInformation
            Resume RemoveBracketExit
        Else
            MsgBox "An error has occurred: " & vbCrLf & _
                   Err.Description & vbCrLf & _
                   "number: " & Err.Number
        End If
    End Sub
    					
  4. Save the module as basRemoveBrackets.
  5. To test the procedure, type the following line in the Immediate window, and then press ENTER

    RemoveBrackets "NameOfDataAccessPage"

    where NameOfDataAccessPage is the name of your page as it appears in the Database window.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

  1. Start Access 2002, and then open the sample database Northwind.mdb.
  2. Create a new query that is based on the Invoices query and include all fields.
  3. Add the following criteria to the OrderID field in the new query:

    In (10248, 10249, 10250)

  4. Save the query as qryThreeInvoices.
  5. Open the Invoice report in Design view, and then change the RecordSource property of the report to qryThreeInvoices.
  6. On the File menu, click Save As, click Data Access Page in the As drop-down list, and then click OK. Click OK when you are prompted for a file name.

    Note that the all fields on the data access page are bound.
  7. Open the data access page in Design view.
  8. Right-click the page, and then click Page Properties.
  9. Click the Data tab, and then change the UseXMLData property to True.
  10. On the Tools menu, point to Macro, and then click Visual Basic Editor.
  11. In the Immediate window, type the following line, and then press ENTER:

    DataAccessPages(0).MSODSC.ExportXML

  12. Return to Access, view the page in Page view, and note that only fields in the details section are bound.

Modification Type:MinorLast Reviewed:9/27/2006
Keywords:kbbug kbDAP kbnofix KB287445