Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighting Text in a Memo Field

Status
Not open for further replies.
Mar 1, 2001
2
US
Does anyone know a VBA routing that will highlight each and every string in a memo field.

For example if the hit is "net" then all instances of any string containing "net" will hightlight.

This is exactly what technet does but I need the code to apply it in an Access Database.

Thanks - Michael
 
I've done this quite a while back. If I recall correctly, and I do, you can't use a standard textbox control to accomplish this. The control must have a means of specifying the beginning and ending characters for the selected text. I used a rich text control which allows the developer to select text but I could only select a single string. If anyone else has the answer we could use some support.

Steve King
 
You can use SelStart and SelLength to highlight one instance of the value in a Textbox, but not all of them. This example uses a textbox named txtNotes and a command button, that when clicked prompts the user to enter the value to search for. Then searches the RecordsetClone for the first record to match that value, resets the Recordset to match that record and highlights that value in the textbox.

Private Sub cmdFind_Click()
Dim strSearch As String, intWhere As Integer
' Get search string from user.
strSearch = InputBox("Enter text to find:")
With Me.RecordsetClone
.MoveFirst
Do While Not .EOF
If InStr(![Notes], strSearch) > 0 Then
intWhere = InStr(![Notes], strSearch)
DoCmd.GoToRecord , , acGoTo, Me.RecordsetClone.AbsolutePosition + 1
txtNotes.SetFocus
txtNotes.SelStart = intWhere - 1
txtNotes.SelLength = Len(strSearch)
GoTo ExitDo
End If
.MoveNext
Loop

' Notify user.
MsgBox "String not found."
ExitDo:
End With
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top