Solved

loop from listview

Posted on 2007-03-19
2
205 Views
Last Modified: 2012-06-21
this is what im using to select the next record from my listview
but how can I make something so when it gets to the end
it goes back to the first record?

Private Sub SelectNextOne()
    With lvwMain
        If Not .SelectedItem Is Nothing Then
            If .SelectedItem.Index < .ListItems.Count And .ListItems.Count > 1 Then
                .ListItems(.SelectedItem.Index + 1).Selected = True
            End If
        End If
    End With
End Sub
0
Comment
Question by:Sabrin
2 Comments
 
LVL 6

Expert Comment

by:saravananvg
ID: 18746883
Hello Sir,

  I think the condition should be
 if .SelectedItem.Index <= ListItems.Count -1 And .ListItems.Count > 1

with regards,
padmaja.
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 18747193
Try this


Private Sub SelectNextOne()
    With lvwMain
        If Not .SelectedItem Is Nothing Then
            If .SelectedItem.Index < .ListItems.Count And .ListItems.Count > 1 Then
                .ListItems(.SelectedItem.Index + 1).Selected = True
            Else
                .ListItems(1).Selected = True
            End If
        End If
        .SetFocus
    End With
End Sub
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro: print each sheet to pdf using ExportAsFixedFormat 11 48
How to debug this code 7 61
Microsoft Access combo box help 2 47
Added a column screws up code 5 57
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question