Compile Error / Variable not Defined

Tina Brev

Registered User.
Local time
Today, 22:53
Joined
Oct 26, 2000
Messages
25
Hello!

Help! Can anyone figure out what's the error in this code. I get a compile error/variable not defined and to be specific, points to this line of code. The NameToSearch turns black.

' Search for the name that the user entered.
For RecNum = 1 To LastRecord
Get #FileNum, RecNum, TmpPerson
If NameToSearch = UCase(Trim(TmpPerson.Name)) Then ......

Here's the code:

Private Sub cmdSearch_Click()

Dim NameToSearch As String
Dim Found As Integer
Dim RecNum As Long
Dim TmpPerson As PersonInfo

' Get the name to search from the user.
NameToSearch = InputBox("Enter the name to search", _
"Search")
' If the user did not enter a name, then exit
' from this procedure.
If IsNull(NameToSearch) Then

' Give the focus to the txtName field.
txtName.SetFocus

' Exit the procedure.
Exit Sub

End If

' Convert the name to be searched to upper case.
NameToSearch = UCase(NameToSearch)

' Initialize the Found flag to False.
Found = False

' Search for the name that the user entered.
For RecNum = 1 To LastRecord
Get #FileNum, RecNum, TmpPerson
If NameToSearch = UCase(Trim(TmpPerson.Name)) Then

Found = True
Exit For
End If

Next

' If the name was found then display the record
' of the found name.
If Found = True Then
SaveCurrentRecord
CurrentRecord = RecNum
ShowCurrentRecord
Else
MsgBox "Name " + NameToSearch + " not found!"
End If

' Give the focus to the txtName field.
txtName.SetFocus

End Sub

Thank You!

Very frustrated.
 
I don't see you define LastRecord or set any value to it.

Or is that a global variable you have initialized somewhere previously?


ntp
 
Hello!

Thank you for your reply. I posted this question in another site/forum and that's exactly the same comment received.

Thanks again for the feedback.
 

Users who are viewing this thread

Back
Top Bottom