Check Please (my code I mean) (1 Viewer)

wizcow

Registered User.
Local time
Today, 06:24
Joined
Sep 22, 2001
Messages
236
This is a peice of code I adapted from Jack Austin.

My form has an unbound textbox where I enter search criteria. (txtSearch)
The search is performed on a memo textbox called (Notes)

The problem I have is that it will only search with in the record that is open.
Jack Austin's Access97 demo works properly. (it searches all records)
In my Access2000 it does not go to the next record, it searches only the open record.

I'm hoping one of you vb Guru's can look at this code and tell me whats wrong.

Code:
Option Compare Database
Option Explicit
Dim strSearch As String, intWhere As Integer


Private Sub Command74_Click()

On Error Resume Next
If IsNull(Me!Notes) Or IsNull(Me!txtSearch) Then Exit Sub

intWhere = Len(Me!txtSearch) 'find the length of the string in Notes

If strSearch = 0 Then strSearch = 1
strSearch = InStr(strSearch, Me!Notes, Me!txtSearch)

    If strSearch > 0 Then
    Me!Notes.SetFocus
    Me!Notes.SelStart = strSearch - 1
    Me!Notes.SelLength = intWhere
    strSearch = strSearch + 1
Else
    strSearch = 1
    Dim rs As Recordset
    Set rs = Me.Recordset
    rs.Bookmark = Me.Bookmark '
    rs.MoveNext
        If rs.EOF Then
        If MsgBox("You are at the end of the table, there are no more records to display." & vbCrLf & "Do you wish to search the records from the beginning for a different word or phrase?", vbDefaultButton2 + vbYesNo + vbQuestion, "What Is Your Pleasure?") = vbYes Then
            rs.MoveFirst
            Me.Bookmark = rs.Bookmark
            Me!txtSearch = Null
            Me!txtSearch.SetFocus
            'TimeCounter = 0
        Else
        End If
    Else
    Me.Bookmark = rs.Bookmark
    
    End If
    Set rs = Nothing
End If

End Sub

Thanks
Tom
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:24
Joined
Aug 30, 2003
Messages
36,126
First thing I would check is the form's recordsource. The search is based on that:

Set rs = Me.Recordset
 

wizcow

Registered User.
Local time
Today, 06:24
Joined
Sep 22, 2001
Messages
236
Thanks for the reply Paul

I have put several records in the forms table.
In the search field 'Notes', I have entered names. I put several names in each record. I put the same name in many of the records too.

If I use the name 'Bill' for a search criteria, it should show up a number of times in the record set, but doesn't.
If I click into record 001 and run the search code, Access finds the name 'Bill' but when I run the code again, the search ends with the msgbox line ,saying I'm at the end of the table. It should move to the next record, because the name 'Bill is in record 001, 003 and 004.

Hope that makes sense!

Tom
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:24
Joined
Aug 30, 2003
Messages
36,126
Can you post a sample? Easier to play with the real thing.
 

wizcow

Registered User.
Local time
Today, 06:24
Joined
Sep 22, 2001
Messages
236
I hope this makes more sense.

Thanks
Tom
 

Attachments

  • Search Example.zip
    35.5 KB · Views: 99

Users who are viewing this thread

Top Bottom