Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching a grid with .findfirst & .findnext

Status
Not open for further replies.

Nicholas

IS-IT--Management
Feb 2, 2000
15
0
0
US
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 = &quot;[TaskDescription]Like '*&quot; & strQuery & &quot;*'&quot;<br>
<br>
With GridRS<br>
If lblTaskViewSearch.Caption = &quot;Next&quot; 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 = &quot;Find&quot; Then<br>
.MoveLast<br>
.FindFirst strQuery<br>
lblTaskViewSearch.Caption = &quot;Next&quot;<br>
End If<br>
<br>
If .NoMatch Then<br>
Beep<br>
' Open the default error message<br>
msgStop!lblStopMessage = &quot;My apologies but I could not find any records to match your search.&quot;<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 = &quot;Find&quot;<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 &quot;Oh No! An Unexpected Error &quot; & Err.Number & &quot;: &quot; & vbCrLf & Err.Description & &quot; with &quot; & Err.Source, vbCritical, &quot;Error With Viewing Closed Tasks&quot;<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
 
Nick,<br>
<br>
I'm sorry mate - but your post is too long for me to read.<br>
<br>
If you'd like to cut your question down to the specific issue you'd like to talk about I'm more than happy to look at it with you.<br>
<br>
Mike<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top