473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Highlighting search field.

PhilOfWalton
1,430 Expert 1GB
I have a continuous form with 4 phone fields on it (Let's call them Phone1 ... Phone 4) (They are text fields)

I have a textbox (TxtPhoneFilter) in the form footer where I enter part of the phone number.

On the OnChange of TxtPhoneFilter, I build a filter something like

Expand|Select|Wrap|Line Numbers
  1. Sub TxtPhoneFilter_Change()
  2.  
  3.     Dim PhoneFltr As String
  4.  
  5.     ' If we return no records, tempotarily remove the filter
  6.     If Me.RecordsetClone.RecordCount = 0 Then
  7.         Me.FilterOn = False
  8.     End If
  9.  
  10.     If Nz(TxtPhoneFilter) = "" Then
  11.         Me.FilterOn = False
  12.     End If
  13.  
  14.     TxtPhoneFilter.SetFocus
  15.  
  16.     If PhoneFltr > "" Then                               ' Media Type selected
  17.         PhoneFltr = PhoneFltr & ") OR "
  18.     End If
  19.     PhoneFltr = PhoneFltr & "(sPhone1 Like '*" & Replace(Me.TxtPhoneFilter.Text, "'", "''") & "*'"
  20.     If PhoneFltr > "" Then                               ' Media Type selected
  21.         PhoneFltr = PhoneFltr & ") OR "
  22.     End If
  23.     PhoneFltr = PhoneFltr & "(Phone2 Like '*" & Replace(Me.TxtPhoneFilter.Text, "'", "''") & "*'"
  24.     If PhoneFltr > "" Then                               ' Media Type selected
  25.         PhoneFltr = PhoneFltr & ") OR "
  26.     End If
  27.     PhoneFltr = PhoneFltr & "(Phone3 Like '*" & Replace(Me.TxtPhoneFilter.Text, "'", "''") & "*'"
  28.     If PhoneFltr > "" Then                               ' Media Type selected
  29.         PhoneFltr = PhoneFltr & ") OR "
  30.     End If
  31.     PhoneFltr = PhoneFltr & "(Phone4 Like '*" & Replace(Me.TxtPhoneFilter.Text, "'", "''") & "*'"
  32.     PhoneFltr = PhoneFltr & ")"
  33.  
  34.     Me.Form.Filter = PhoneFltr
  35.     Me.FilterOn = True
  36.  
  37.     Me.TxtPhoneFilter.SetFocus
  38.  
  39.     ' Move the cursor to the end of the input text box.
  40.     If Me.RecordsetClone.RecordCount = 0 Then
  41.         Exit Sub
  42.     End If
  43.  
  44.     Me.TxtPhoneFilter.SelStart = Len(Me.TxtPhoneFilter.Text)
  45.  
This woks very sweetly and progressively filters the form, showing fewer and fewer records as more letters (digits) of the phone number are entered into TxtPhoneFilter.

So suppose we are down to 6 records = 24 phone numbers.

Now what I want to do is to highlight only those phone numbers that match TxtPhoneFilter.

Stymied. Any ideas please?

Phil
Jan 20 '17 #1
5 1393
PhilOfWalton
1,430 Expert 1GB
Sorry, I withdraw the question. Solved it

Phil
Jan 20 '17 #2
zmbd
5,501 Expert Mod 4TB
You could share how.... :)
Personally, I would look at the potential of conditional formatting or even add the formatting to your existing code...
There's a nice little blog here that walks thru creating and adding the formatting conditions by VBA
https://blogs.msdn.microsoft.com/fri...cess-with-vba/
:)
Jan 20 '17 #3
PhilOfWalton
1,430 Expert 1GB
What give away my trade secrets ... alright then.

I created 4 text boxes with the control source like this
IsPhone1 ControlSource

Expand|Select|Wrap|Line Numbers
  1. =IIf(Nz([TxtPhoneFilter])>"",IIf([Phone1] Like "*" & [TxtPhoneFilter] & "*",True,False),False)
  2.  
Then conditional formatting like this
Expression is IsPhone1 True then the alternative format.

Works a treat.

Phil
Jan 20 '17 #4
jforbes
1,107 Expert 1GB
Sounds like you go it. I was working on something like this recently, so I mocked up a DB for ya and attached it anyway.

It uses RichText formatted TextBoxes which allows for some creative coloring.
Attached Files
File Type: zip Highlight.zip (26.8 KB, 86 views)
Jan 21 '17 #5
PhilOfWalton
1,430 Expert 1GB
Yes that' very neat. The main difference obviously is that you are highlighting individual figures whilst I am highlighting the whole phone number.

Anyway your Db now sits in my sample Db folder were I have loads of bits and pieces for reference for a rainy day..
Thanks again

Phil
Jan 21 '17 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: leegold2 | last post by:
I've seen previous threads but I still need help in highlighting search terms like google does on their search result page. I know I need, ob_start(); Then I process to highlight the search term...
1
by: Mario | last post by:
I am trying to set up a search field that searches my only my website. I dont want to link it to other search engines. It is only for the web im developing. Any Links or Suggestions on how to...
4
by: Captain Wonky | last post by:
As the subject says... I'm a database novice even though I've been trying to learn Access for years. I've 'almost finished' several databases but always get stumped on something - this time it's...
1
by: Raterus | last post by:
Does anyone know of some code samples that will parse a string field into an array of strings, but do it like a search engine would. I'm sure this would be fun to do it myself, but if an algorithm...
2
by: AA Arens | last post by:
When I push on my find-record button, after I focussed on the ID-number field on my form, the default search field in the Search-form dialog menu is not the focussed field, but another. Why? ...
0
by: Jon | last post by:
If anyone can help...Whenevr I go into a form and use the ctrl+F to find something with the binoculars the "Search field as formatted" is checked as default. This seems to slow down the find...
3
mmarif4u
by: mmarif4u | last post by:
Hi everyone, I have a little problem in php coding. i have mysql table guestbook: Fields are Id,name,email,comment,datetime. Now i want to search the database by php query using a Dropdown menu...
2
by: ZEROFIVE | last post by:
Just wanted to know how would i go about making a Search field and search results page if someone wanted to search on my site? Thanks alot, Jimmy
1
by: brenty66 | last post by:
I have a userform that is used as an interface for information stored on excel spreadsheets. The user enters bits of information into fields on the userform which are place on the corresponding...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.