PDA

View Full Version : Access VBA Listview



calvinle
09-11-2014, 12:47 PM
Hi guys,

I am new to VBA Access, and I will need to work with ListView because that is the most thing that I am familiar with but on Excel.

Because I am using Access to manipulate an external application, so I will not need to store any data in the tables in Access, but only need it as a compiler for the VBA macro. I have used Excel userform, but due to the fact that many of my data is in Excel, it's not pleasant to switch from Userform Excel to Excel sheet, back and forth.

So I want to use Access VBA to control the external application.

All I need to do is to have a ListView in Access with preloaded items in 4 category in vba code.

Here is what I have started



Option Compare Database
Private Sub cmdRetrieve_Click()
Call Retrieve
End Sub
Private Sub Retrieve()
'On Error GoTo EXIT_DOOR
Dim ListView1 As MSComctlLib.ListView

With ListView1
'.ListItems.Clear
.ListItems.Add , , "Data 1"
.ListItems(i).ListSubItems.Add , , "Data 2"
.ListItems(i).ListSubItems.Add , , "Data 3"
.ListItems(i).ListSubItems.Add , , "Data 4"

End With
End Sub


Hope anyone can help.

jonh
09-12-2014, 02:03 AM
Private Sub cmdRetrieve_Click()
'On Error GoTo EXIT_DOOR
Dim ch As ColumnHeader, li As ListItem
Dim LV As MSComctlLib.ListView
Set LV = ListView1.Object

LV.ColumnHeaders.Clear
LV.ListItems.Clear

'create headers
For i = 1 To 4
LV.ColumnHeaders.Add , , "hdr " & i
Next

'add some data
For i = 1 To 10
Set li = LV.ListItems.Add(, , i & " itm 1")
li.ListSubItems.Add , , i & " sub 1"
li.ListSubItems.Add , , i & " sub 2"
li.ListSubItems.Add , , i & " sub 3"
Next

'report view
LV.View = 3
End Sub