Solved

Change Default Font for Lebans RTF Control

Posted on 2004-04-25
17
604 Views
Last Modified: 2013-12-03
Does someone know how to change the default font that is used for the Lebans RTF Control?  Presently, the font used is System, but I would like to change it to something else.  Thanks.
0
Comment
Question by:DanielAttard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 4
17 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 10912788
can you not simply set the font name in code

e.g.

Not sure, but it might be font

<control>.Font = "MS Sans Serif"

if control is on form , I think its Me.<control>.Object.Font = ...

0
 

Author Comment

by:DanielAttard
ID: 10913072
When would I set this?  Would it be with the OnLoad event of the form?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10913740
My previous post was a question considering I havent used Lebans

but with Microsoft Rich Textbox control, you can set the font name, simply <controlname>.Font = "MS Sans Serif"

Ive just installed Lebans, and I cant see the font property

there is fontitalic, fontbold and fontunderline

I successfully set the backcolor

rtfLebans.Object.Backcolor = 0   'rtfLebans is the name of my control

I set italiics by doing rtfLebans.Object.FontItalic = True

So sorry, I not sure of the property is available, thru design

BUT I tried it thru code

to see the properties available in code, do this

dim x as new RTF2
x.

after hitting dot, you will see a list of properties available
I found a Font property but cant seem to get it going

So I tried a different way, not sure how your gonna like this but, I dumped the contents of my control

rtfLebans.Object.RTFText and it came up with this

(this is rtf code)

{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fprq2\fcharset0 System;}}
\viewkind4\uc1\pard\tx1440\tx2880\tx4320\tx5760\tx7200\tx8640\tx10080\tx11520\tx12960\tx14400\tx15840\tx17280\tx18720\tx20160\tx21600\tx23040\tx24480\tx25920\tx27360\tx28800\tx30240\tx31680\tx33120\tx34560\tx36000\tx37440\tx38880\tx40320\tx41760\tx43200\tx44640\tx46080\f0\fs20 fred\b\par
}


where fred (towards the end) is my text

you will see the word System, that appears to be your font

I changed it to Impact, split the string up and it worked!!!

e.g.
    Dim x1 As String, x2 As String, x3 As String
   
    x1 = "{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fprq2\fcharset0 Impact;}}"
    x2 = "\viewkind4\uc1\pard\tx1440\tx2880\tx4320\tx5760\tx7200\tx8640\tx10080\tx11520\tx12960\tx14400\tx15840\tx17280\tx18720\tx20160\tx21600\tx23040\tx24480\tx25920\tx27360\tx28800\tx30240\tx31680\tx33120\tx34560\tx36000\tx37440\tx38880\tx40320\tx41760\tx43200\tx44640\tx46080\f0\fs20 "
    x3 = "\b\par}"
   
    rtfLebans.Object.rtfText = x1 & x2 & x3


I put this in the Form_Load function so the rtf control has font in


bit awkward but cant find any other way

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:jjafferr
ID: 10915774
Hi guys, I went through this before, and this was my solution:

I open the RTFform from another Form, once it is loaded, place this code right after the open Form code, like this:
docmd.openform ......

'To make the font Tahoma instead of the default System: Replace System;}} with Tahoma;}}
'To make the font normal instead of Bold: Replace \b\f with \f
      Forms![RTFformName].Refresh
      Forms![RTFformName]![Body] = Replace(Forms![Body Text-Decline]![Body], "System;}}", "Tahoma;}}")
      Forms![RTFformName]![Body] = Replace(Forms![Body Text-Decline]![Body], "\b\f", "\f")

It works fine for me

jaffer
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10916439
yea, I suppose thats another way of doing it, change the font text in the rtf string using the Replace command
good un Jaffer
but took me awhile to figure out where the font name was stored
0
 
LVL 27

Expert Comment

by:jjafferr
ID: 10916462
Thanks rockiroads,
yet you brought to my attention my wrong syntax (I changed part and forgot the other part), so this is how it should look:


'To make the font Tahoma instead of the default System: Replace System;}} with Tahoma;}}
'To make the font normal instead of Bold: Replace \b\f with \f
      Forms![RTFformName].Refresh
      Forms![RTFformName]![Body] = Replace(Forms![RTFformName]![Body], "System;}}", "Tahoma;}}")
      Forms![RTFformName]![Body] = Replace(Forms![RTFformName]![Body], "\b\f", "\f")

jaffer
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10916480
just one point Jaffer

to make it bold,you dont need to change the RTF text, just the property like I described earlier
e.g.
rtfLebans.Object.FontItalic = True

0
 
LVL 27

Expert Comment

by:jjafferr
ID: 10916510
You are right,

this eample shows how to handle
Font Name
and
Font Normal (instead of the default Bold)

they both are not controlable from anywhere else, unlike FontItalic

You can use each one seperatly though if you wish.

jaffer
0
 

Author Comment

by:DanielAttard
ID: 10918056
Thanks for your help with this guys.  I appreciate it.

Jaffer - I am trying to implement your suggestion, but don't fully understand this part of what you said:

"I open the RTFform from another Form, once it is loaded, place this code right after the open Form code, like this:
docmd.openform ......"

Does this mean that I have to create another form object just to do this?  I'm not exactly sure of where to put your code?  What event do I attach it to on what form?  Thanks.
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
ID: 10918199
Jaffers approach in changing font is like mine, except Ive gone the long way round

in your Form_Load function

change your font there

The Replace command substitutes from the given string one text for another
e.g. Replace(xyz,"ss",tt") will replace in the string xyz, change ss to tt
Replace returns the modified string

Forms![RTFformName]![Body] = Replace(Forms![Body Text-Decline]![Body],"System;}}", "Tahoma;}}")

is the same as doing

Me.<rtfControlName>.Body = Replace(Me.<rtfControlName>.Body, "System;}","Tahoma;}"

I havent tried the .Body property, Im assuming it does, I tried the rtfText property, that worked

0
 
LVL 27

Expert Comment

by:jjafferr
ID: 10918380
Hi DanielAttard

How do you open the RTFform?
I assume you open it by pressing on a command button, lets call it command1, so your code will be

Private Sub Command1_Click()

    stDocName = "RTFformName"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
   
End Sub

change it to

Private Sub Command1_Click()

    stDocName = "RTFformName"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
   
'To make the font Tahoma instead of the default System: Replace System;}} with Tahoma;}}
      Forms![RTFformName].Refresh
      Forms![RTFformName]![Body] = Replace(Forms![RTFformName]![Body], "System;}}", "Tahoma;}}")

End Sub

jaffer
0
 

Author Comment

by:DanielAttard
ID: 10919159
Thanks for the continued help, I'm almost there, but not quite yet.

The RTF control I am using is on my startup form.  It opens automatically.  It is bound to a Memo.  I use my startup form to scroll through records for which the memo field is usually blank.  This means (I think) that both the Memo field itself is blank, and the RTF control is blank.  The moment I start typing in the RTF control, I want it to be in Rotis font but I can't seem to make this happen.

If I attach your code to the form Load event, this may work for the current record, but I think that it would lose its formatting when I scroll from record to record.  Also, I'm not even sure the code will work if the Memo field is empty.  I am getting an error message saying "Invalid Use of Null".

Perhaps the time to run the code might be when I start typing in the RTF control?  Sorry to be such a pain about this, but I truly appreciate your help!
0
 
LVL 27

Assisted Solution

by:jjafferr
jjafferr earned 250 total points
ID: 10919252

Put the code in On Current of the Form,

if you still kept getting the error message, then

Before the code, lets write a space in the field, which will not make the field Null, so the code looks like this:

      Forms![RTFformName]![Body]=" "  'OR Forms![RTFformName]![Body]=chr(32)
      Forms![RTFformName].Refresh
      Forms![RTFformName]![Body] = Replace(Forms![RTFformName]![Body], "System;}}", "Rotis;}}")

jaffer
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10919271
to keep it going from record to record, do the same in the Form_Current event

in fact, create a procedure within your form then simply call that procedure

e.g.

private sub ChangeFont()
   rtfLens......
end sub


private sub Form_Load()
    ChangeFont
end sub


private sub Form_Current
    ChangeFont
end sub

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10919310
with null, use NZ

NZ(<string>,'')

basically if your string is null then substitute with '' (empty string)
that removes the null error

you can wrap this round the replace statement
0
 

Author Comment

by:DanielAttard
ID: 10924656
Thanks for all the help guys.  I managed to get the functionality I was looking for through a combination of both of your suggestions.  I appreciate your input.

During the time we were trying to figure this out, I did receive an email from Stephen Lebans and he gave me a suggestion for how to change the default font.  Here is the code that he gave me.  I wasn't able to get it working, but perhaps one of you might know how to implement it, if you're interested.  I didn't know where to put it.  Here it is:

 Dim x As RTF2
    Dim fnt As New StdFont

    Set x = Me!rtfControl.Object
    With fnt
        .Name = "arial"
        .Size = 14
        .Italic = False
        .Bold = False
        .Strikethrough = False
        .Underline = False
    End With

    set x.Font = fnt
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10926356
In my earlier post, I told you about how I managed to find the font property in code

dim x as new RTF2
x.Font was found but couldnt get it working

Ive tried the above (though I used Font instead of StdFont) and I get the same problem

0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question