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.
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.