kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
Hello everyone, I have this challenge here and I want you to help me out.
This is filling the textboxes when double clicked.
This one is the next button:
This one populates the listbox:
So my mission now is to get the selection move in the listbox as I click the next button.
Thanks
Kelly
This is filling the textboxes when double clicked.
Code:
Private Sub lstView_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim n As Integer, ac As Integer, i As Integer
i = Me.lstView.ListIndex
With lstView
For ac = 1 To .ColumnCount
.TextColumn = ac
Me.Controls("Rw" & ac).Value = .Text
Next ac
CmdEdit.Enabled = True
CmdDelete.Enabled = True
CmdAdd.Enabled = False
End With
End Sub
This one is the next button:
Code:
Private Sub CmdNext_Click()
Dim FindRow As Range, i As Long, cNum As Long, x As Long, r As Long, cRow As String, sht As String
sht = ComboBox1.Value
On Error Resume Next
cRow = Me.Rw1.Value
Set FindRow = Sheets(sht).Range("B7:B250").Find(What:=cRow, LookIn:=xlValues)
If FindRow Is Nothing Then Exit Sub
r = IIf(Len(FindRow.Offset(1, 0).Text) = 0, 0, 1)
cNum = 22
For x = 1 To cNum
Me.Controls("Rw" & x).Value = FindRow.Offset(r, 0).Text
Set FindRow = FindRow.Offset(0, 1)
Next
If r = 0 Then MsgBox "Last Record reached in the database", vbInformation, "Last Record Alert!"
On Error GoTo 0
End Sub
This one populates the listbox:
Code:
Sub Lookup()
On Error GoTo errHandler:
lstView.ColumnCount = 22
Dim myArray As Variant
myArray = [B2].Resize(, lstView.ColumnCount + 2).Value
lstView.List = myArray
lstView.Clear
sht = ComboBox1.Value
With Sheets(sht).Range("B7:B250")
Set rngFind = .Find(txtSearch.Text, After:=Sheets(sht).[B250], LookIn:=xlValues, lookat:=xlPart, _
SearchDirection:=xlNext)
If Not rngFind Is Nothing Then
strFirstFind = rngFind.Address
Do
If rngFind.Row > 1 Then
lstView.AddItem rngFind.Text
For i = 1 To 22
lstView.List(lstView.ListCount - 1, i) = rngFind.Offset(0, i).Text
Next i
End If
Set rngFind = .FindNext(rngFind)
Loop While Not rngFind Is Nothing And rngFind.Address <> strFirstFind
Else: 'Reset1
MsgBox "No match found for: " & "'" & txtSearch.Text & "'", vbInformation, "Match Alert"
End If
End With
On Error GoTo 0
Exit Sub
errHandler::
MsgBox "Check your entry for errors"
End Sub
So my mission now is to get the selection move in the listbox as I click the next button.
Thanks
Kelly