1 Search Box for Multiple Fields

SantasLittleHelper

Board Regular
Joined
Nov 25, 2016
Messages
77
I have the code below linked to a text box on a Form. It searches 2 fields for the textbox value. Is there any way I can edit it so it searches for values which contain the textbox value? At the moment it is only searching or an exact match... E.g. If I search 'Test' it will not show 'Test123' in the results.

Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Private SubText142_AfterUpdate()[/COLOR][/SIZE][/FONT]


[FONT=Calibri][SIZE=3][COLOR=#000000]    Dim Fltr As String[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]     Fltr = "Email1 = " &Chr$(34) & Text142 & Chr$(34)[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]     Fltr = Fltr & " OR Email2= " & Chr$(34) & Text142 & Chr$(34)[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]     Me.Filter = Fltr[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]     Me.FilterOn = True[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]     Me.Requery[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Use * on either side of the control value and change = to Like ?
 
Upvote 0
No need for requery
Code:
Private SubText142_AfterUpdate()
    Dim Fltr As String

     Fltr = "Email1 Like '*" & Text142 & "*'"
     Fltr = Fltr & " OR Email2 Like '*" & Text142 & "*'"

     Me.Filter = Fltr
     Me.FilterOn = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top