LikeButtah1
New Member
- Joined
- Apr 17, 2018
- Messages
- 34
Hello All,
I am trying to find the next record of the same last name that the user will type into textbox1. I can have another button to navigate through the records but after finding the last record it should say "Last Record Found". Column A holds the last names and first record starts in A3. Here is the code that finds the first instance of the last name in textbox1:
Any help would be great. Thanks in advance.
I am trying to find the next record of the same last name that the user will type into textbox1. I can have another button to navigate through the records but after finding the last record it should say "Last Record Found". Column A holds the last names and first record starts in A3. Here is the code that finds the first instance of the last name in textbox1:
Code:
Dim blnNew As Boolean
Dim TRows, i As Long
Private Sub btnLName_Click()
blnNew = False
txtLastName.Text = ""
txtFirstName.Text = ""
txtC.Text = ""
txtNewCard.Text = ""
txtAccDes.Text = ""
txtAccCreated.Text = ""
txtAccGranted.Text = ""
txtAccCancelled.Text = ""
txtAccCategory.Text = ""
txtNotes.Text = ""
TRows = Worksheets("PNG Database").Range("A1").CurrentRegion.Rows.Count
For i = 3 To TRows
If LCase(Worksheets("PNG Database").Cells(i, 1).Value) = LCase(TextBox1.Text) Then
txtLastName.Text = Worksheets("PNG Database").Cells(i, 1).Value
txtFirstName.Text = Worksheets("PNG Database").Cells(i, 2).Value
txtC.Text = Worksheets("PNG Database").Cells(i, 3).Value
txtNewCard.Text = Worksheets("PNG Database").Cells(i, 4).Value
txtAccDes.Text = Worksheets("PNG Database").Cells(i, 5).Value
txtAccCreated.Text = Worksheets("PNG Database").Cells(i, 6).Value
txtAccGranted.Text = Worksheets("PNG Database").Cells(i, 7).Value
txtAccCancelled.Text = Worksheets("PNG Database").Cells(i, 8).Value
txtAccCategory.Text = Worksheets("PNG Database").Cells(i, 9).Value
txtNotes.Text = Worksheets("PNG Database").Cells(i, 12).Value
Exit For
End If
Next i
End Sub
Any help would be great. Thanks in advance.