Tag: userform button

Next – Previous Buttons on Userform

Select Listbox Item With Next – Previous Buttons

User can view the records with previous control and next control buttons easily .Also in this form,

If you click “cmdfirst” button, the form goes to the first record.Or If you click “cmdlast” button, the form goes to the last record.While viewing records on listbox, you can see the order of records in “textBox6”.

Select listbox item with next previous buttons

Nature picture was used as background of the this userform.

Codes of Previous Button :
If ListBox1.ListIndex = 0 Then
MsgBox “First Record”, vbCritical
Exit Sub
Else
TextBox6 = TextBox6 – 1
With Me.ListBox1
.ListIndex = .ListIndex – 1
End With
End If

Codes of Next Button :
If ListBox1.ListIndex = ListBox1.ListCount – 1 Then
MsgBox “Last Record”, vbCritical
Exit Sub
Else
TextBox6 = TextBox6 + 1
With Me.ListBox1
.ListIndex = .ListIndex + 1
End With
End If

⇒ Sample File Can Be Downloaded Here