Total Visual SourceBook

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office 2007 and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!

Separate version for Access/Office 2003, 2002, and 2000.

Separate version for:
Access 97/95


View all FMS products for Microsoft AccessAll Our Microsoft Access Products

SourceBook Info:

Why SourceBook?

 

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

 

 

 

Microsoft Access, Office/VBA, VB6 Modules royalty-free source code libraryMicrosoft Access Modules royalty-free source code libraryMicrosoft Access VBA and VB6 Module Library Free trial of Total Visual SourceBook for Microsoft Access, Office, VB6 and VBA

Module: ListView in Category ActiveX Controls : Common Controls from Total Visual SourceBook

Routines to extend the functionality of the VB6 ListView control.

The majority of the ListView enhancements are provided in the CListViewEnh class. This module contains a standalone procedure to load a DAO recordset into a ListView control. Note that this code is not supported in the 64-bit version of Access 2010 or 2013 due to the use of the Common Controls of MSComCtl32.ocx.

Procedure List

Procedure Name

Type

Description

(Declarations) Declarations Declarations and private variables for the modListView module
ADORecordSetToListView Procedure Loads the contents of an ADO recordset in a standard unbound listview control from left to right until it runs out of available columns in the ListView control. If you want to see the columns in a different order, select them in the desired order from the query that creates the recordset.
RecordSetToListView Procedure Loads the contents of a DAO recordset in a standard unbound listview control from left to right until it runs out of available columns in the ListView control. If you want to see the columns in a different order, select them in the desired order from the query that creates the recordset.

Example Code for Using Module: ListView

' Example of modListView
' This example assumes Access VBA as the host language

' 1. Create a new form
' 2. Add a ListView control called 'lvwProducts'
'    Set the following properties
'    View            3 - lvwReport
'    ColumnHeaders - Insert 4 column headers
' 3. Add a CommandButton control called 'cmdDAO'
' 4. Add a CommandButton control called 'cmdADO'
' 5. Paste all the code from this example to the new form's module.
' 6. Run the form to load the listview control

' This example assumes that the sample files are located in the folder named by the following constant.
Private Const mcstrSamplePath As String = "C:\TVSBSamp"
Private Const mcstrConnect As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mcstrSamplePath & "\sample.mdb"

Private Sub Form_Load()
  cmdADO.Caption = "Load with ADO"
  cmdDAO.Caption = "Load with DAO"

End Sub

Private Sub cmdDAO_Click()

  Dim dbs As DAO.Database
  Dim rst As DAO.Recordset
  Dim strSQL As String

  strSQL = "SELECT Products.ProductID, Products.ProductName, Categories.CategoryName, Suppliers.CompanyName, Suppliers.ContactName " & _
           "FROM Suppliers " & _
           "INNER JOIN (Categories " & _
           "INNER JOIN Products " & _
           "ON Categories.CategoryID = Products.CategoryID) " & _
           "ON Suppliers.SupplierID = Products.SupplierID"

  Set dbs = DAO.DBEngine(0).OpenDatabase(mcstrSamplePath & "\sample.mdb")

  Set rst = dbs.OpenRecordset(strSQL, dbOpenSnapshot)

  Screen.MousePointer = vbHourglass

  ' Example of RecordSetToListView
  ' Load the recordset into the listview, using the value in the ProductID column as they listitem key,
  ' and the value in the Subject column as the 'tag' property of the listitem
  RecordSetToListView rst, lvwProducts.Object, "ProductID", "ProductName"

  Screen.MousePointer = vbDefault

End Sub

Private Sub cmdADO_Click()
  Dim rstProducts As ADODB.Recordset
  Dim strSQL As String

  strSQL = "SELECT Products.ProductID, Products.ProductName, Categories.CategoryName, Suppliers.CompanyName " & _
    "FROM Suppliers " & _
    "INNER JOIN (Categories INNER JOIN Products " & _
    "ON Categories.CategoryID = Products.CategoryID) " & _
    "ON Suppliers.SupplierID = Products.SupplierID " & _
    "ORDER BY Products.ProductName "

  Set rstProducts = New ADODB.Recordset
  rstProducts.Open strSQL, mcstrConnect

  ' Example of ADORecordSetToListView
  ' Load the recordset into the listview, using the value in the ProductID column as they listitem key.
  ADORecordSetToListView rstProducts, lvwProducts.Object, "ProductID"

End Sub

Microsoft Access Module LibraryOverview of Total Visual SourceBook

The source code in Total Visual SourceBook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Additional Resources