We help IT Professionals succeed at work.

MS Access ListView Control not working

COPUSER
COPUSER asked
on
Experts,

I have a form with a ListView control on it.  Whenever I run the code to load the listview, I get the error 380 "Invalid Property value".  The code is listed below.

    Dim rs As New ADODB.Recordset
    Dim lstItem As ListItem

    rs.MoveFirst
    Do While Not rs.EOF
        Set lstItem = MyListView.ListItems.Add()
        lstItem.Text = rs.Fields("StudyID")
        lstItem.SubItems(1) = rs.Fields("StudyName")
        lstItem.SubItems(2) = Nz(rs.Fields("StudyMonth"), "")
        lstItem.SubItems(3) = Nz(rs.Fields("StudyYear"), "")
        rs.MoveNext
     Loop

I've tried both re-register mscomctl.ocx and reinstall mscomctl.ocx but nothing worked.

Can anyone shed some light on this?
Comment
Watch Question

Try to reference the ListView directly like this:

  Dim rs As New ADODB.Recordset

    rs.MoveFirst
    Do While Not rs.EOF
        With Me.MyListView.ListItems.Add()
          lstItem.Text = rs.Fields("StudyID")
          lstItem.SubItems(1) = rs.Fields("StudyName")
          lstItem.SubItems(2) = Nz(rs.Fields("StudyMonth"), "")
          lstItem.SubItems(3) = Nz(rs.Fields("StudyYear"), "")
        End With
      rs.MoveNext
     Loop

Hope this helps,
Daniel

Author

Commented:
Daniel,

It was the first thing I did and it did not work.
Check below thread and sample on the syntax:
http://support.microsoft.com/kb/155178

Hope this helps,
Daniel
This is the more recent version of the same article:
http://support.microsoft.com/kb/210006

Hope this helps,
Daniel
Top Expert 2006

Commented:
I assume that is just a snippet of the code as I do not see where you open the recordset
when you said you tried registering the ocx, did it come up as dll succeeded?
if you do not get any errors for that control when opening the form then it should of been registered fine
which line is it failing on, did u try place a break point then step thru?

Author

Commented:
I figured out why the listview control was not loading properly.  I relied on the column heading setting I placed on the ListViewCtrlObject properties page.  When I explicitly set the column heading properties via code, the rest of the code worked without a glitch.  I still don't know why setting column header properties via control's property setting page will not work.  Thanks for all the comments.