Get values from ListView (1 Viewer)

rkaptu

Registered User.
Local time
Today, 15:01
Joined
Oct 27, 2017
Messages
19
Hi all

I feel like I am missing out something. I want to create a control on a form listing a number of options (taken from a query) with checkboxes next to each item so use can select which is needed (then will be used to populate a new form used later on for something else).

I have managed to create the control using Microsoft ListView Control Ver. 6, and populate with the list of items and check boxes.

But how do I get the data of what user has selected? I guess it has to be in the control's 'On Item Click' Event, and when I did try some code there this was happening whenever I clicked on any item. But how do I get the information of which items have been clicked?

I suspect its something simple... but I cannot get it!:mad::(

I called control ListView1. Form is called Form1. I am using Access 2007
 

Minty

AWF VIP
Local time
Today, 23:01
Joined
Jul 26, 2013
Messages
10,371
Use an inbuilt multi select Access listbox.
Using any of the active x / external controls is making very hard work for yourself.

There are some examples of their use in the sample database section.
 

MarkK

bit cruncher
Local time
Today, 15:01
Joined
Mar 17, 2004
Messages
8,181
So are you successfully handling the ListView.ItemClick event in your code? If so, the clicked ListItem is present in the signature of the event, and that ListItem exposes a collection called ListSubItems, which are the values of each of the columns.

But maybe show some code, and we can see more about what is going on.

hth
Mark
 

rkaptu

Registered User.
Local time
Today, 15:01
Joined
Oct 27, 2017
Messages
19
Thanks Minty and MarkK

I do not like the standard listbox options since I do not find them so user friendly when using a long list and needing to have a clear indication of what is chosen and what is not.

As to the Listview I have used a code I found around to populate the listview:

" 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 'Report'.

' 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(, , 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"

And then I am calling the function like this:

Private Sub Form_Load()

Call FillList("Query for Cards 2", ListView1)

End Sub

And it works: capture-20171215-142421.png

Question is how can I, maybe in an event following the click of a button I can add on the form, get the reference to the rows user clicks? Otherwise the whole think is useless...
 

Users who are viewing this thread

Top Bottom