Search subform for a word or phrase (1 Viewer)

Bobp3114

Member
Local time
Today, 16:12
Joined
Nov 11, 2020
Messages
42
I have a form (frmContactDetailsPower) with a form (frmProgressiveNotesEntryPower) linked by [StationID] from txtStationID. Form frmProgressiveNotesEntryPower is linked to a table (tblProgressiveNotes). I need to be able to search the table (limited by the StationID) for each instance of a word or phrase to locate a particular record.
At present I am converting the records to Word an using that search ability. Is there a quicker, better way to accomplish this?
Thanks, Bob
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:12
Joined
Oct 29, 2018
Messages
21,449
I am thinking you might be able to use a query. For example,

SQL:
SELECT * FROM TableName WHERE NotesID=1 AND NotesField Like "*searchword*"
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:12
Joined
May 7, 2009
Messages
19,228
maybe a sample will help (or confuse?) you.
see the Click event of search button.
 

Bobp3114

Member
Local time
Today, 16:12
Joined
Nov 11, 2020
Messages
42
I am thinking you might be able to use a query. For example,

SQL:
SELECT * FROM TableName WHERE NotesID=1 AND NotesField Like "*searchword*"
Thanks mate
will work on that approach
Bob
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:12
Joined
May 7, 2009
Messages
19,228
i forget the sample demo, here it is.
 

Attachments

  • contactDetails.accdb
    672 KB · Views: 306

Bobp3114

Member
Local time
Today, 16:12
Joined
Nov 11, 2020
Messages
42
i forget the sample demo, here it is.
Hi
I have adapted your code to suit, and it works to find the first matching record...how do I get it to move to the next matching record
This form is not a subform but one that opens with an ID from the previous form
Here is my code:
Private Sub cmdSearch_Click()
On Error GoTo Err_cmdSearch_Click
Dim sobForm As Form

Set sobForm = Forms("frmProgressiveNotesEntryRF")
If Len(Me.txtSearch & "") <> 0 Then
With sobForm.RecordsetClone
If Me.cmdSearch.Caption = "Submit Search" Then
.FindFirst "Notes Like '*" & Replace$(Me!txtSearch, "'", "''") & "*'"
If Not .NoMatch Then
sobForm.Bookmark = .Bookmark
Me.cmdSearch.Caption = " "
Else
MsgBox "No matching record found"
End If
Else
.Bookmark = sobForm.Bookmark
.FindNext "Notes Like '*" & Replace$(Me!txtSearch, "'", "''") & "*'"
If .NoMatch Then
Me.cmdSearch.Caption = "Submit Search"
MsgBox "No more matching record"
Else
sobForm.Bookmark = .Bookmark
End If
End If
End With
Else
MsgBox "please type something to search."
Me.txtSearch.SetFocus
End If
Exit_cmdSearch_Click:
Exit Sub

Err_cmdSearch_Click:
MsgBox Err.Description
Resume Exit_cmdSearch_Click
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:12
Joined
May 7, 2009
Messages
19,228
see this other demo
 

Attachments

  • contactDetails.accdb
    684 KB · Views: 308

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:12
Joined
Feb 19, 2002
Messages
43,213
The Access GUI provides search features. You don't need code or queries. Click into the field you want to search and press the binoculars to bring up the search dialog.
 

Users who are viewing this thread

Top Bottom