ACC97: Listview Control Loses Data When Changing Properties

Last reviewed: August 29, 1997
Article ID: Q166912
The information in this article applies to:
  • Microsoft Access 97

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you toggle the Visible or Enabled properties of a ListView control, the control loses its records by approximately one-half each time those properties are cycled.

NOTE: This occurs with Microsoft ListView Control, version 5.0, which is available with Microsoft Office 97 Developer Edition Tools.

RESOLUTION

Each time you toggle the Enabled or Visible properties of the ListView control, clear the ListView control and rerun code to fill the control with data. You can use the Clear method of the ListItems collection in the control to remove all the items. The following example uses a command button to toggle the Visible property of a ListView control without losing rows of data:

  1. Perform steps 1 - 7 in the "Steps to Reproduce Problem" section below.

  2. Add a command button to the form. Set its Name property to Command0, and set its OnClick property to the following event procedure:

          Private Sub Command0_Click
    
             Dim db As Database, rs As Recordset
             Dim itmX As ListItem
             Set db = CurrentDb()
             Set rs = db.OpenRecordset("Employees", dbOpenDynaset)
    
             ' Toggle the Visible property of the control.
             Me!ListView1.Visible = Not Me!ListView1.Visible
    
             ' Clear and then refill the control with data.
             While Not rs.EOF
                Set itmX = ListView1.ListItems.Add(, , CStr(rs![FirstName] ))
                If Not IsNull(rs![LastName]) Then
                   itmX.SubItems(1) = CStr(rs![LastName])
                End If
                If Not IsNull(rs![BirthDate]) Then
                   itmX.SubItems(2) = rs![BirthDate]
                End If
                rs.MoveNext
             Wend
          End Sub
    
    

  3. Save the form as frmListView, and then switch it to Form view. Note that as you click the command button to toggle the Visible property of the ListView control, the number of records displayed in the control remains the same.

STATUS

Microsoft has confirmed this to be a problem in Microsoft Office 97 Developer Edition Tools. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The Microsoft ListView Control, version 5.0, is one of the controls included in the ActiveX control file, Comctl32.ocx. This behavior exists in version 5.00.3601 of Comctl32.ocx.

Steps to Reproduce Problem

  1. Start Microsoft Access and open the sample database Northwind.mdb.

  2. Create a new form not based on any table or query in Design view.

  3. On the Insert menu, click ActiveX Control.

  4. In the Insert ActiveX Control dialog box, select Microsoft ListView Control, version 5.0, and then click OK.

  5. Set the following properties of the ListView control:

          Name: ListView1
          Width: 4"
          Height: 2"
    

  6. On the View menu, click Code.

  7. Type the following procedure, which populates the ListView control with data when you open the form:

          Private Sub Form_Open(Cancel As Integer)
    
             Dim db As Database, rs As Recordset
             Dim itmX As ListItem
             Set db = CurrentDb()
             Set rs = db.OpenRecordset("Employees", dbOpenDynaset)
    
             ListView1.ColumnHeaders.Add, , "First Name", ListView1.Width/3
             ListView1.ColumnHeaders.Add, , "Last Name", _
                ListView1.Width/3, lvwColumnCenter
             ListView1.ColumnHeaders.Add, , "Birthdate", _
                ListView1.Width/3
             ListView1.View = lvwReport
    
             While Not rs.EOF
                Set itmX = ListView1.ListItems.Add(, , CStr(rs![FirstName] ))
                If Not IsNull(rs![LastName]) Then
                   itmX.SubItems(1) = CStr(rs![LastName])
                End If
                If Not IsNull(rs![BirthDate]) Then
                   itmX.SubItems(2) = rs![BirthDate]
                End If
                rs.MoveNext
             Wend
          End Sub
    
    

  8. Add a command button named Command0 to the form, and set its OnClick property to the following event procedure:

          Private Sub Command)_Click()
    
             Me!ListView1.Enabled = Not Me!ListView1.Enabled
          End Sub
    
    

  9. Save the form as frmListView, and then switch it to Form view. Note that as you click the command button to toggle the Enabled property of the ListView control, the number of records displayed in the control reduces by about half. However, after the number of records is reduced to one, the last record continues to display even if you continue to click the command button.

REFERENCES

For more information about the ListView control, search the Help Index for "ListView control."


Additional query words: disappear reduce diminish
Keywords : IntpCstm kbinterop kbprg
Version : 97
Platform : WINDOWS
Hardware : x86
Issue type : kbbug
Solution Type : kbcode


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.