Here is my issue: I have on my form a textbox and label. The label acts as a button (you'll see) to perform the search on a grid in which each row is a record.<br>
<br>
(1) I have tried to detect .EOF so that the search might .movefirst and begin from the top again with no success.<br>
<br>
(2) I also want to use the InStr to highlight the word on the grid but I always receive 13-Type Mismatch.<br>
<br>
Here is the code I am using for reference:<br>
<br>
' *******************************************<br>
' * Search function<br>
' *******************************************<br>
Private Sub lblTaskViewSearch_Click()<br>
On Error GoTo ERR_lblTaskViewSearch_Click<br>
<br>
Set GridRS = GridTaskViewMain.Recordset<br>
Set msgStop = New msgStop<br>
<br>
strQuery = Trim$(TxtTaskViewSearch.Text)<br>
If Len(strQuery) = 0 Then Exit Sub<br>
strQuery = "[TaskDescription]Like '*" & strQuery & "*'"<br>
<br>
With GridRS<br>
If lblTaskViewSearch.Caption = "Next" Then<br>
If .EOF = False Then<br>
.FindNext strQuery<br>
End If<br>
If .AbsolutePosition + (1) = .EOF Then<br>
.MoveFirst<br>
.FindFirst strQuery<br>
End If<br>
End If<br>
If lblTaskViewSearch.Caption = "Find" Then<br>
.MoveLast<br>
.FindFirst strQuery<br>
lblTaskViewSearch.Caption = "Next"<br>
End If<br>
<br>
If .NoMatch Then<br>
Beep<br>
' Open the default error message<br>
msgStop!lblStopMessage = "My apologies but I could not find any records to match your search."<br>
msgStop.Show 1<br>
Set msgStop = Nothing<br>
' Select the entered text for query<br>
TxtTaskViewSearch.SelStart = 0<br>
TxtTaskViewSearch.SelLength = Len(TxtTaskViewSearch.Text)<br>
' Move to the first record to restart search<br>
.MoveFirst<br>
lblTaskViewSearch.Caption = "Find"<br>
Exit Sub<br>
End If<br>
<br>
If Not .NoMatch Then<br>
GridTaskViewMain.MoveToBookmark GridRS.Bookmark<br>
End If<br>
<br>
End With<br>
Exit Sub<br>
ERR_lblTaskViewSearch_Click:<br>
MsgBox "Oh No! An Unexpected Error " & Err.Number & ": " & vbCrLf & Err.Description & " with " & Err.Source, vbCritical, "Error With Viewing Closed Tasks"<br>
Resume Next<br>
End Sub <p>Nicholas, BofA NetOps<br><a href=mailto: > </a><br><a href= > </a><br>Biologically Classified as Alpha-Geek 234
<br>
(1) I have tried to detect .EOF so that the search might .movefirst and begin from the top again with no success.<br>
<br>
(2) I also want to use the InStr to highlight the word on the grid but I always receive 13-Type Mismatch.<br>
<br>
Here is the code I am using for reference:<br>
<br>
' *******************************************<br>
' * Search function<br>
' *******************************************<br>
Private Sub lblTaskViewSearch_Click()<br>
On Error GoTo ERR_lblTaskViewSearch_Click<br>
<br>
Set GridRS = GridTaskViewMain.Recordset<br>
Set msgStop = New msgStop<br>
<br>
strQuery = Trim$(TxtTaskViewSearch.Text)<br>
If Len(strQuery) = 0 Then Exit Sub<br>
strQuery = "[TaskDescription]Like '*" & strQuery & "*'"<br>
<br>
With GridRS<br>
If lblTaskViewSearch.Caption = "Next" Then<br>
If .EOF = False Then<br>
.FindNext strQuery<br>
End If<br>
If .AbsolutePosition + (1) = .EOF Then<br>
.MoveFirst<br>
.FindFirst strQuery<br>
End If<br>
End If<br>
If lblTaskViewSearch.Caption = "Find" Then<br>
.MoveLast<br>
.FindFirst strQuery<br>
lblTaskViewSearch.Caption = "Next"<br>
End If<br>
<br>
If .NoMatch Then<br>
Beep<br>
' Open the default error message<br>
msgStop!lblStopMessage = "My apologies but I could not find any records to match your search."<br>
msgStop.Show 1<br>
Set msgStop = Nothing<br>
' Select the entered text for query<br>
TxtTaskViewSearch.SelStart = 0<br>
TxtTaskViewSearch.SelLength = Len(TxtTaskViewSearch.Text)<br>
' Move to the first record to restart search<br>
.MoveFirst<br>
lblTaskViewSearch.Caption = "Find"<br>
Exit Sub<br>
End If<br>
<br>
If Not .NoMatch Then<br>
GridTaskViewMain.MoveToBookmark GridRS.Bookmark<br>
End If<br>
<br>
End With<br>
Exit Sub<br>
ERR_lblTaskViewSearch_Click:<br>
MsgBox "Oh No! An Unexpected Error " & Err.Number & ": " & vbCrLf & Err.Description & " with " & Err.Source, vbCritical, "Error With Viewing Closed Tasks"<br>
Resume Next<br>
End Sub <p>Nicholas, BofA NetOps<br><a href=mailto: > </a><br><a href= > </a><br>Biologically Classified as Alpha-Geek 234