Font will not change on Memo field (1 Viewer)

epiek

Registered User.
Local time
Today, 22:44
Joined
Jul 25, 2011
Messages
35
I have an URGENT issue to solve, please...

I have a form where several Rich text memo fields are being used

The users often copy and paste from Word into these fields.

I want to change the font with coding so that all the font on all the fields look similar.

I have used specifc reference to the fields and trying to code them all eg.

Me.FindingDetail.FontName = "Tahoma"
Me.FindingDetail.FontSize = 8
Me.Criteria.FontName = "Tahoma"
Me.Criteria.FontSize = 8

also tried:

Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then

ctl.FontName = "Tahoma"
ctl.FontSize = 8

End If
Next

Neither of these work.
 

nschroeder

nschroeder
Local time
Today, 14:44
Joined
Jan 8, 2007
Messages
186
Since it's a Rich Text field, the formatting is imbedded in the text. I found this out by putting a debug stop in the AfterUpdate event of a rich text memo field. I then typed "This is a test" in a Word document in Algerian font, then copied and pasted it to the field. In the Immediate pane, what it showed was:

Code:
?me.Memotest.Value
<div><font face=Algerian color=black>This is a test</font></div>
If you put the following code in AfterUpdate, it will clean it up, leaving only the text:

Code:
Private Sub Memotest_AfterUpdate()
Dim i1 As Integer, i2 As Integer, i3 As Integer
    With Memotest
        i1 = InStr(1, .Value, "<font")
        If i1 > 0 Then
            i2 = InStr(i1, .Value, ">")
            If i2 > 0 Then
                i3 = InStr(i2, .Value, "</")
                If i3 > 0 Then
                    .Value = Mid(.Value, i2 + 1, i3 - 1 - i2)
                End If
            End If
        End If
    End With
End Sub

This will work as long as the there is no mixing of fonts, highlights, colors, etc. within the text value being pasted in. If there is, the imbedded value you get could look something like:

Code:
<div><font face=Algerian color=red>This</font><font face=Algerian color=black> </font><font
face=Algerian color=black style="BACKGROUND-COLOR:#FFFF00">is a test</font></div>

If that's a possiblity, you would need to get more extensive with your cleanup code, but this should get you started.
 

nschroeder

nschroeder
Local time
Today, 14:44
Joined
Jan 8, 2007
Messages
186
Here's some improved code that would handle the mixed fonts, etc.

Code:
Private Sub Memotest_AfterUpdate()
Dim sVal As String, i1 As Integer, i2 As Integer
    With Memotest
        If Left(.Value, 6) = "<div><" And Right(.Value, 6) = "</div>" Then
            i2 = 7 ' Starting point
            Do Until i2 = 0 ' No more "<" found
                i1 = InStr(i2, .Value, ">")
                i2 = InStr(i1, .Value, "<")
                If i2 > 0 Then
                    sVal = sVal & Mid(.Value, i1 + 1, i2 - i1 - 1)
                End If
            Loop
            .Value = sVal
        End If
    End With
End Sub

The only limitation is if the incoming text included legimitate "<" or ">" characters. Then the results would be unpredictable.
 

Users who are viewing this thread

Top Bottom