Silvio said:
OK I got it to work. I needed to set focusn on the list first and use
.ListIndex. For everyone's benefit here is the full working codes:
Private Sub GoBack_Click()
Me.MyFiles.SetFocus
If Me.MyFiles.ListIndex > 0 Then
Me.MyFiles.ListIndex = Me.MyFiles.ListIndex - 1
Else
Me.MyFiles.ListIndex = Me.MyFiles.ListCount - 1
End If
End Sub
Private Sub GoNext_Click()
Me.MyFiles.SetFocus
If Me.MyFiles.ListIndex < Me.MyFiles.ListCount - 1 Then
Me.MyFiles.ListIndex = Me.MyFiles.ListIndex + 1
Else
Me.MyFiles.ListIndex = 0
End If
End Sub
Thank you Stuart for your help!
I forgot the need to give the listbox focus, sorry.
Ok now we've established that it does indeed work, let's tidy it up a bit:
Private Sub GoBack_Click()
With Me.MyFiles
.SetFocus
.ListIndex = Iif(.ListIndex > 0, .ListIndex - 1, .ListCount - 1)
End With
End Sub
Private Sub GoNext_Click()
With Me.MyFiles
.SetFocus
.ListIndex = Iif(.ListIndex < .ListCount - 1, .ListIndex + 1, 0)
End With
End Sub
A lot easier to read, I think you'll agree.