ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
I am using the code shown below.
I type in TextBox1 & press return on the keyboard to start the search.
I see a Msgbox appear advising NO USER NAME FOUND
I then click ok BUT im now expecting to see the cursor flashing in TextBox1 but its not.
I get no error messages either.
Do you see a reason why.
Thanks
I type in TextBox1 & press return on the keyboard to start the search.
I see a Msgbox appear advising NO USER NAME FOUND
I then click ok BUT im now expecting to see the cursor flashing in TextBox1 but its not.
I get no error messages either.
Do you see a reason why.
Thanks
Rich (BB code):
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbKeyReturn Then
Dim r As Range, f As Range, cell As String, added As Boolean
Dim sh As Worksheet
Set sh = Sheets("POSTAGE")
sh.Select
With ListBox1
.Clear
.ColumnCount = 4
.ColumnWidths = "240;150;280;50"
If TextBox1.Value = "" Then Exit Sub
Set r = Range("I8", Range("I" & Rows.Count).End(xlUp))
Set f = r.Find(TextBox1.Value, LookIn:=xlValues, LookAt:=xlPart)
If Not f Is Nothing Then
cell = f.Address
Do
added = False
For i = 0 To .ListCount - 1
Select Case StrComp(.List(i), f.Value, vbTextCompare)
Case 0, 1
.AddItem f.Value, i 'Item
.List(i, 3) = f.Row 'Row Number
.List(i, 2) = f.Offset(, -7).Value 'Customer
.List(i, 1) = f.Offset(, -2).Text 'Date
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value 'Item
.List(.ListCount - 1, 3) = f.Row 'Row Number
.List(.ListCount - 1, 2) = f.Offset(, -7).Value 'Customer
.List(.ListCount - 1, 1) = f.Offset(, -2).Text 'Date
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> cell
TextBox1 = UCase(TextBox1)
.TopIndex = 0
Else
MsgBox "NO USER NAME WAS FOUND USING THAT INFORMATION", vbCritical, "POSTAGE SHEET USER NAME SEARCH"
TextBox1.Value = ""
ListBox1.Clear
TextBox1.SetFocus
End If
End With
End If
End Sub