-1

I have problem with check the last element in list in ms access and put the last value to label. I have used a loop to realize this:

Private Sub lstAbgänge_DblClick(Cancel As Integer)

i = 0
r = 0

Do Until Me.lstAbgänge.Column(0, i) = Null
   i = i + 1
   r = Me.lstAbgänge.Column(0, i)
   If r = Null Then Exit Do
Loop

'Me.lblVorgangNr.Caption = Me.lstAbgänge.Column(0, i - 1)

End Sub

My problem is that loop is neverending, I have tried end this loop by condition "Me.lstAbgänge.Column(0, i) = Null" and next by "If r = Null Then Exit Do" but in both cases it doesn't work. When it has value Null loop is still working.

View of list in form Debbuging

Beacze
  • 534
  • 3
  • 8
  • 24

1 Answers1

2

Try something like this:

Private Sub lstAbgänge_DblClick(Cancel As Integer)

    Dim i as Integer
    For i = 0 to Me.lstAbgänge.ListCount - 1
        Debug.Print Me.lstAbgänge.Column(0, i)
    Next i

End Sub

You need to use the ListCount property to iterate to the end of the list.

See this post: cycling through values in a MS Access list box

Community
  • 1
  • 1
HK1
  • 11,941
  • 14
  • 64
  • 99