Link to home
Start Free TrialLog in
Avatar of COPUSER
COPUSER

asked on

MS Access ListView Control not working

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?
Avatar of danishani
danishani
Flag of United States of America image

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
Avatar of COPUSER
COPUSER

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of danishani
danishani
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rockiroads
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?
Avatar of COPUSER

ASKER

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.