Results 1 to 8 of 8

Thread: Image List must be initialized before it can be used.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2013
    Posts
    100

    Image List must be initialized before it can be used.

    GOod afternoon,
    I am new to VB6 however relatively experienced in VBA.

    I am attempting to load information into a ListView control via an Access DB. I have placed the following code into the form_load event.

    However I receive an error on the highlighted line: "Image List must be initialized before it can be used".

    When I initially added the listview, I right clicked on the control and selected properties. I have the view set as '3 - lvwReport'. I set up my 5 columns by going to the Column Headers tab and entering each. However when I go to Image Lists, all the drop downs show '<none>'

    Thoughts?

    Code:
    Private Sub Form_Load()
    Dim MyConn As ADODB.Connection
    
    Set MyConn = New ADODB.Connection
    MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\Business Intelligence\VB6\Database9.mdb;"
    MyConn.Open
    
    Dim strSQL As String 'our query string
    Dim oRS As ADODB.Recordset 'our recordset object
    Dim lvwItem As ListItem 'this is necessary to directly reference the ListView control
    Set oRS = New ADODB.Recordset
     
    'change this SQL as appropriate for your needs
    strSQL = "SELECT Date_Entered, Loan_Number, Investor, State, Doc_type FROM MailTeamTracker "
    'change oConn to reflect the Connection object you are using in your program
    oRS.Open strSQL, MyConn, adOpenForwardOnly, adLockReadOnly
     
    'load the listview
    Do While Not oRS.EOF
       Set lvwItem = ListView1.ListItems.Add(, , oRS.Fields.Item("Date_Entered").Value, "mm/dd/yyy")
       lvwItem.SubItems(1) = oRS.Fields.Item("Loan_Number").Value
       'change the date format as required
       lvwItem.SubItems(2) = Format(oRS.Fields.Item("Investor").Value)
       lvwItem.SubItems(3) = oRS.Fields.Item("State").Value
       'change the date format as required
       lvwItem.SubItems(4) = Format(oRS.Fields.Item("Doc_Type").Value)
       oRS.MoveNext
    Loop
    oRS.Close
    Set oRS = Nothing
    
    
      End Sub

  2. #2
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: Image List must be initialized before it can be used.

    I ran into this once and it almost gave me a coronary. I'm so sorry you found this. Unfortunately, I don't recall how I resolved the issue, but a search of these forums found this solution:

    Quote Originally Posted by emyztik View Post
    The error, as you know, is "ImageList must be initialized before it can be used."

    EDIT: Resolved by right clicking the listview, choosing "Properties", click on "Image Lists", and set all three combos to "ImageList".

    Also, google search pointed me to a few threads that suggest solutions:
    http://forums.devx.com/showthread.ph...lization-Error
    http://vbcity.com/forums/t/112295.aspx

    Unfortunately, this is the best I can do for you. Good luck!

  3. #3
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Image List must be initialized before it can be used.

    I suspect you need
    Code:
    Set lvwItem = ListView1.ListItems.Add(, , Format(oRS.Fields.Item("Date_Entered").Value, "mm/dd/yyy"))

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Image List must be initialized before it can be used.

    you need to add an imagelist to your form... add some images to it... then point your ListView to the ImageList... then you should be able to add new lsit view items, and set the icon at the same time.

    And there is Doogle's solution too...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Image List must be initialized before it can be used.

    Just to expand on my earlier thought. The 4th argument of the .Add method for a ListView Listitem is the Icon. OP has specified "mm/dd/yy" which led me to believe that they were really trying to format a Date rather than use an icon named "mm/dd/yy".

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2013
    Posts
    100

    Re: Image List must be initialized before it can be used.

    Please see below. Accidental double post.
    Last edited by MWhiteDesigns; Jun 18th, 2013 at 07:45 AM. Reason: accidental

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2013
    Posts
    100

    Re: Image List must be initialized before it can be used.

    THank you guys for your help.

    I have been able to edit the code and it does pull in the values correctly now.

    I read somewhere that with the report view, the image was optional, thats why I did not included it after the date.

    I removed the area in red and it worked fine.

    Code:
    Do While Not oRS.EOF
       Set lvwItem = ListView1.ListItems.Add(, , oRS.Fields.Item("Date_Entered").Value, "mm/dd/yyy"))
       lvwItem.SubItems(1) = oRS.Fields.Item("Loan_Number").Value
       lvwItem.SubItems(2) = Format(oRS.Fields.Item("Investor").Value)
       lvwItem.SubItems(3) = oRS.Fields.Item("State").Value
       lvwItem.SubItems(4) = Format(oRS.Fields.Item("Doc_Type").Value)
       oRS.MoveNext
    Loop
    As I said before. I am pretty fluent in VBA, but getting into VB im a bit lost in some places. Especially in the area of talking back and forth to the server. You'll be seeing alot of me! Thanks again!
    Last edited by MWhiteDesigns; Jun 18th, 2013 at 09:58 AM.

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Image List must be initialized before it can be used.

    This line should still fail...
    Set lvwItem = ListView1.ListItems.Add(, , oRS.Fields.Item("Date_Entered").Value, "mm/dd/yyy"))

    just on parenthesis alone... you have 2 opening and 3 closing...

    probably because you meant to use the FORMAT option, as Doogle was trying to point out...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width