×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Searching a grid with .findfirst & .findnext

Searching a grid with .findfirst & .findnext

Searching a grid with .findfirst & .findnext

(OP)
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.

(1) I have tried to detect .EOF so that the search might .movefirst and begin from the top again with no success.

(2) I also want to use the InStr to highlight the word on the grid but I always receive 13-Type Mismatch.

Here is the code I am using for reference:

' *******************************************
' * Search function
' *******************************************
Private Sub lblTaskViewSearch_Click()
On Error GoTo ERR_lblTaskViewSearch_Click

Set GridRS = GridTaskViewMain.Recordset
Set msgStop = New msgStop

strQuery = Trim$(TxtTaskViewSearch.Text)
If Len(strQuery) = 0 Then Exit Sub
strQuery = "[TaskDescription]Like '*" & strQuery & "*'"

With GridRS
If lblTaskViewSearch.Caption = "Next" Then
If .EOF = False Then
.FindNext strQuery
End If
If .AbsolutePosition + (1) = .EOF Then
.MoveFirst
.FindFirst strQuery
End If
End If
If lblTaskViewSearch.Caption = "Find" Then
.MoveLast
.FindFirst strQuery
lblTaskViewSearch.Caption = "Next"
End If

If .NoMatch Then
Beep
' Open the default error message
msgStop!lblStopMessage = "My apologies but I could not find any records to match your search."
msgStop.Show 1
Set msgStop = Nothing
' Select the entered text for query
TxtTaskViewSearch.SelStart = 0
TxtTaskViewSearch.SelLength = Len(TxtTaskViewSearch.Text)
' Move to the first record to restart search
.MoveFirst
lblTaskViewSearch.Caption = "Find"
Exit Sub
End If

If Not .NoMatch Then
GridTaskViewMain.MoveToBookmark GridRS.Bookmark
End If

End With
Exit Sub
ERR_lblTaskViewSearch_Click:
MsgBox "Oh No! An Unexpected Error " & Err.Number & ": " & vbCrLf & Err.Description & " with " & Err.Source, vbCritical, "Error With Viewing Closed Tasks"
Resume Next
End Sub

Nicholas, BofA NetOps


Biologically Classified as Alpha-Geek 234

RE: Searching a grid with .findfirst & .findnext

Nick,

I'm sorry mate - but your post is too long for me to read.

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.

Mike

Mike Lacey
Mike_Lacey@Cargill.Com
Cargill's Corporate Web Site

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close