Results 1 to 2 of 2
  1. #1
    Kananelo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2011
    Posts
    7

    Cool How to add image/icon to a listview

    Goodday folks!

    I simply need help, i have a code that loads data from my table into a listview in an access form.

    I need to add a SmallImage to the listview.

    Thank you.



    Code:
    Option Explicit
     Function FillList(Domain As String, LV As Object) As Boolean
          '==================================================================
          '  Purpose:   to fill a ListView control with data from a table or
          '             query
          '  Arguments: a Domain which is the name of the table or query, and
          '             a ListView control object
          '  Returns:   A Boolean value to indicate if the function was
          '             successful
          '==================================================================
          Dim db As Database, rs As Recordset
          Dim intTotCount As Integer
          Dim intCount1 As Integer, intCount2 As Integer
          Dim colNew As ColumnHeader, NewLine As ListItem
     
          On Error GoTo Err_Man
          ' Clear the ListView control.
          LV.ListItems.Clear
          LV.ColumnHeaders.Clear
          ' Set Variables.
          Set db = CurrentDb
          Set rs = db.OpenRecordset(Domain)
          ' Set Column Headers.
          For intCount1 = 0 To rs.Fields.Count - 1
             Set colNew = LV.ColumnHeaders.Add(, , rs(intCount1).Name)
          Next intCount1
          LV.View = 3    ' Set View property to 'Details'.
          LV.GridLines = True
          LV.FullRowSelect = True
     
     
          ' Set Total Records Counter.
          rs.MoveLast
          intTotCount = rs.RecordCount
          rs.MoveFirst
          ' Loop through recordset and add Items to the control.
          For intCount1 = 1 To intTotCount
             If IsNumeric(rs(0).Value) Then
                Set NewLine = LV.ListItems.Add(, , Str(rs(0).Value))
             Else
                Set NewLine = LV.ListItems.Add(, , Str(rs(0).Value))
             End If
             For intCount2 = 1 To rs.Fields.Count - 1
                NewLine.SubItems(intCount2) = rs(intCount2).Value
             Next intCount2
             rs.MoveNext
          Next intCount1
          Exit Function
    Err_Man:
             ' Ignore Error 94 which indicates you passed a NULL value.
             If Err = 94 Then
                Resume Next
             Else
             ' Otherwise display the error message.
                MsgBox "Error: " & Err.Number & Chr(13) & _
                   Chr(10) & Err.Description
             End If
    End Function

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Google: vba image in listview

    Here is one http://www.vbforums.com/showthread.php?t=530678
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-10-2011, 10:58 AM
  2. Add records to treeview and listview
    By goodguy in forum Forms
    Replies: 6
    Last Post: 10-04-2011, 04:26 PM
  3. Filter listview
    By JJCHCK in forum Programming
    Replies: 2
    Last Post: 09-23-2011, 10:24 AM
  4. Listview pulling data from a second table
    By Yesideez in forum Access
    Replies: 8
    Last Post: 06-29-2011, 05:08 AM
  5. Transfer data from ListView to Table
    By Zyckie in forum Access
    Replies: 1
    Last Post: 12-15-2009, 11:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums