PDA

View Full Version : Solved: Searching a very specific Value



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

Bob Phillips
04-11-2007, 04:51 AM
Set c = .Find(strFind, LookIn:=xlValues, LookAt:=xlWhole)

jammer6_9
04-11-2007, 05:07 AM
that was a quick and precise reply xld... thanks...

In addition to that erorr, if i enter a more than 6 digit employee no. error comes out.

Run Time Error 6

Overflow

Debugging to the code below


strFind = Me.TextBox1.Value

jammer6_9
04-11-2007, 05:08 AM
textbox1 means the txtEmpNo


that was a quick and precise reply xld... thanks...

In addition to that erorr, if i enter a more than 6 digit employee no. error comes out.

Run Time Error 6

Overflow

Debugging to the code below


strFind = Me.TextBox1.Value

moa
04-11-2007, 05:11 AM
You should dim the variable as Long not Integer

moa
04-11-2007, 05:14 AM
or String.

jammer6_9
04-11-2007, 05:19 AM
:whistle: I almost done with my project getting codes on VBAX... Thanks a lot people...