fill LISTVIEW WITH CITY, LOCATION AND ZIP

User avatar
sal21
GoldLounger
Posts: 3326
Joined: 26 Apr 2010, 17:36

fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by sal21 »

I have recordset with city, zipcode, and location.

during the a loop, possible to have the result in a listview, with a column name CITY, ZIPCOD, LOCATION, CITY1, ZIPCOD1, LOCATION1, with this sequence, similar, the attached sheet.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 69458
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by HansV »

I'll assume that you have already opened a recordset named rst, and that you have a listview control named ListView1.

Code: Select all

    Dim lvw As ListView
    Dim itm As ListItem
    Dim i As Long
    Dim n As Long
    rst.MoveLast
    rst.MoveFirst
    n = rst.RecordCount
    Set lvw = Me.ListView1
    For i = 1 To n - 1
        Set itm = lvw.ListItems.Add(Text:=rst!CITY)
        itm.ListSubItems.Add Text:=rst!ZIPCOD
        itm.ListSubItems.Add Text:=rst!Location
        rst.MoveNext
        itm.ListSubItems.Add Text:=rst!CITY1
        itm.ListSubItems.Add Text:=rst!ZIPCOD1
        itm.ListSubItems.Add Text:=rst!Location1
    Next i
Regards,
Hans

User avatar
sal21
GoldLounger
Posts: 3326
Joined: 26 Apr 2010, 17:36

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by sal21 »

Sorry, but changed my code....
instead a recordset have this array, can you rearrange?

Code: Select all

For R = 1 To A
        If Me.Controls("LOC" & R).Text > "" Then
            ReDim Preserve RouteL(R)
            With RouteL(I)
                CITTA = Split(Me.Controls("CIT" & R).Text, "-(")(0)
                ZIP= Replace(Split(Me.Controls("CIT" & R).Text, "-(")(1), ")", "")
                LOCALITA = Split(Me.Controls("LOC" & R).Text, "-")(1)
                'LATD = Replace(Split(Me.Controls("LOC" & R).Text, "-")(2), ".", ",")
                'LOND = Replace(Split(Me.Controls("LOC" & R).Text, "-")(3), ".", ",")
            End With
        End If
    Next
NOTE:
the controls are combobox

User avatar
HansV
Administrator
Posts: 69458
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by HansV »

You don't do anything with RouteL(I) so I don't understand what you're doing now.
Regards,
Hans

User avatar
sal21
GoldLounger
Posts: 3326
Joined: 26 Apr 2010, 17:36

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by sal21 »

HansV wrote:
29 Oct 2020, 16:54
You don't do anything with RouteL(I) so I don't understand what you're doing now.
sorry

With RouteL(I)

...



I=I+1

...

User avatar
HansV
Administrator
Posts: 69458
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by HansV »

It doesn't make sense. You don't do anything with RouteL(I) in

With RouteL(I)
...
End With
Regards,
Hans

User avatar
sal21
GoldLounger
Posts: 3326
Joined: 26 Apr 2010, 17:36

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by sal21 »

ops....
see the image.
i need to store the value from each combobox value in array

CITTA = Split(Me.Controls("CIT" & R).Text, "-(")(0)
PR= Replace(Split(Me.Controls("CIT" & R).Text, "-(")(1), ")", "")
LOCALITA = Split(Me.Controls("LOC" & R).Text, "-")(1)
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 69458
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by HansV »

I don't understand this at all, sorry.
Regards,
Hans

User avatar
sal21
GoldLounger
Posts: 3326
Joined: 26 Apr 2010, 17:36

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by sal21 »

Hi bro!
Attached new xls with the position of value in combobox, similar the listview in image.
In effect i need to loop the value in combobox ans paste in listview.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 69458
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by HansV »

How have the combo boxes been populated?
Regards,
Hans

User avatar
sal21
GoldLounger
Posts: 3326
Joined: 26 Apr 2010, 17:36

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by sal21 »

txt code
button draw start all (command1)
You do not have the required permissions to view the files attached to this post.

User avatar
sal21
GoldLounger
Posts: 3326
Joined: 26 Apr 2010, 17:36

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by sal21 »

HansV wrote:
30 Oct 2020, 16:50
How have the combo boxes been populated?
for error posted a new comment here, instead to reply you...

User avatar
HansV
Administrator
Posts: 69458
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: fill LISTVIEW WITH CITY, LOCATION AND ZIP

Post by HansV »

The code is far too long for me to analyze, but it seems to me you already use recordsets to populate the combo boxes, so why not use those to populate the listview?
Regards,
Hans