Hei,
I’d like to mark the difference between two text boxes.
I have the following code to open and compare the text but I don’t know how to change the colour of the letter/character which is checked different.
The .selcolor method and Selection.font.colorindex don’t work, the .forecolor isn’t suitable for this.
My textbox is in richtext and I have made use that the form is able to be modified. I checked and I can modify the font colour “by hand” using mouse.
In the end, the form will be opened in hidden mode to hide the macro from the user. Opening the form in hidden mode is the simplest solution I found. Maybe there is better way.
You'll find my current code herebelow.
Thanks for your support.
Bob
I’d like to mark the difference between two text boxes.
I have the following code to open and compare the text but I don’t know how to change the colour of the letter/character which is checked different.
The .selcolor method and Selection.font.colorindex don’t work, the .forecolor isn’t suitable for this.
My textbox is in richtext and I have made use that the form is able to be modified. I checked and I can modify the font colour “by hand” using mouse.
In the end, the form will be opened in hidden mode to hide the macro from the user. Opening the form in hidden mode is the simplest solution I found. Maybe there is better way.
You'll find my current code herebelow.
Thanks for your support.
Bob
Code:
Public Function Compare()
Dim Text1 As String
Dim Text2 As String
Dim filterFrm As String
Dim i As Integer
i = 0
Set db = CurrentDb
PK = 101
filterFrm = "HistID=" & PK
DoCmd.OpenForm "HistList2", acNormal, , WhereCondition:="HistID=" & PK
Set TextBox2 = Forms.HistList2.Texte73
Set TextBox1 = Forms.HistList2!Texte52
Text1 = TextBox1.Value
Text2 = TextBox2.Value
'Compare text from two text boxes and set the colour to red :
For i = 1 To Len(Text2)
If Mid(Text1, i, 1) <> Mid(Text2, i, 1) Then
TextBox2.SetFocus
TextBox2.SelStart = i - 1
TextBox2.SelLength = 1
TextBox2.Selcolor = RGB(255, 0, 0)
End If
Next i
DoCmd.Close acForm, "HistList2", acSaveYes
'Clean variable:
Set TextBox2 = Nothing
Set TextBox1 = Nothing
Set db = Nothing
End Function