jammer6_9
04-11-2007, 04:34 AM
:help I am entering employee No. "617" to search and cmdSearch is working fine but if I enter only "6" to search, it will still search the first employee no. that has "6" and why it does not pop up my msgbox considering that "6" is not an existing employee no...
Private Sub cmdFind_Click()
Dim strFind As Integer, FirstAddress As String
Dim rSearch As Range
Set rSearch = Sheet1.Range("a6", Range("a65536").End(xlUp))
strFind = Me.txtEmpNo.Value
Dim f As Integer
With rSearch
Set c = .Find(strFind, LookIn:=xlValues)
If Not c Is Nothing Then
c.Select
With Me
.txtEmpName.Value = c.Offset(0, 1).Value
.txtEmpPosition.Value = c.Offset(0, 2).Value
.txtEmpSalary.Value = c.Offset(0, 3).Value
.txtHiringDate.Value = c.Offset(0, 4).Value
.cmdEdit.Enabled = True
.cmdDelete.Enabled = True
.cmdAdd.Enabled = False
f = 0
End With
FirstAddress = c.Address
Do
f + 3
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
Else: MsgBox strFind & " Employee Do Not Exist"
End If
End With
End Sub
Private Sub cmdFind_Click()
Dim strFind As Integer, FirstAddress As String
Dim rSearch As Range
Set rSearch = Sheet1.Range("a6", Range("a65536").End(xlUp))
strFind = Me.txtEmpNo.Value
Dim f As Integer
With rSearch
Set c = .Find(strFind, LookIn:=xlValues)
If Not c Is Nothing Then
c.Select
With Me
.txtEmpName.Value = c.Offset(0, 1).Value
.txtEmpPosition.Value = c.Offset(0, 2).Value
.txtEmpSalary.Value = c.Offset(0, 3).Value
.txtHiringDate.Value = c.Offset(0, 4).Value
.cmdEdit.Enabled = True
.cmdDelete.Enabled = True
.cmdAdd.Enabled = False
f = 0
End With
FirstAddress = c.Address
Do
f + 3
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
Else: MsgBox strFind & " Employee Do Not Exist"
End If
End With
End Sub