hi everybody
in ms-access 2010, i have a form with some textbox one of my textbox is p_name textbox over the form a put to different fonts with radio buttons ... i want to change the font of selectedt part of textbox value with radio button font .. when i select part of textbox value and i select another font in radio buttons the font of this part in textbox must change to that new font
10 5635
How many font changes will be in the textbox? For example, if the default font is Calibri, would you only have one section that would be, say, Arial or would you have more sections that would be Times New Roman, Courier New, etc.?
Seth Schrock thank you for your answer
yes i want one section would be another font only , only two font if i select any part of textbox data and click radio button that have arila font for example it must change this part to arila font , befor change it must be another font all textbox data
NeoPa 32,556
Expert Mod 16PB
Is that a new option? It's certainly not something I've ever heard of being possible in a TextBox.
It's possible in an Excel cell, but that's quite another thing.
PS. I've since learned that it is a new option in 2010.
Everything that you are requesting can be done but it must be in a specified manner. I'll create a scenario for you to follow. - Create a Text Box on a Form and name it txtRich.
- Bind this Text Box to a Field whose Data Type is MEMO, namely: set its Control Source to a MEMO Field which is included in the Row Source of the Form.
- In the Table containing this MEMO Field set its Text Format Property to Rich Text.
- Open the Form and select any number of Characters in the txtRich Field.
- You can now modify the Font Characteristics of the Selected Text only, as in:
- Me![txtRich].FontName = "Courier"
- Only the Font of the Selected Text will change to Courier.
- Any questions feel free to ask.
@Adezii, if you use your code, then the whole text box will be changed to the courier font. The OP is only wanting the portion that he selected in the textbox to be changed. I had created a solution, but it is limited to only one change of font. The second change wipes out the first change as it uses the PlainText() function to be able to get the selected text correctly.
I'll see if I can dig up what I did (I think that I saved it) and post back here in a little bit (hopefully).
Okay, here is the environment that I built. I have a form (named frmRichText) that has a textbox (named txtRichText) and an option group (named optFont). The option group has three options (you can add all you want), Times New Roman, Arial and Courier New. I also take back that that you don't need it tied to a Memo field as you do need to make it be a memo field with the text format set to rich text. My testing was without binding the textbox to a data source.
Now, for the code. You need to declare two variables at the module level. I also created an enum for the fonts. - Private Enum ssFont
-
ssTimes = 1
-
ssArial = 2
-
ssCour = 3
-
End Enum
-
-
Private intStart As Integer
-
Private intLength As Integer
In the textbox's MouseUp event, you need the following code. - Private Sub txtRichText_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
-
intStart = Me.txtRichText.SelStart
-
intLength = Me.txtRichText.SelLength
-
-
End Sub
Next, I have the Option Group AfterUpdate event along with a custom function. - Private Sub optFont_AfterUpdate()
-
Dim strTextbox As String
-
Dim strBef As String
-
Dim strSel As String
-
Dim strAft As String
-
Dim font As String
-
-
strTextbox = PlainText(Me.txtRichText)
-
-
strSel = Mid(strTextbox, intStart + 1, intLength)
-
strBef = Left(strTextbox, intStart)
-
strAft = Mid(strTextbox, intStart + intLength + 1)
-
-
Debug.Print strBef, strSel, strAft
-
-
Select Case Me.optFont
-
Case ssTimes
-
font = "Times New Roman"
-
-
Case ssArial
-
font = "Arial"
-
-
Case ssCour
-
font = "Courier New"
-
-
End Select
-
-
Me.txtRichText = "<div>" & strBef & ChangeFont(strSel, font) & strAft & "</div>"
-
-
End Sub
-
-
Private Function ChangeFont(Value As String, font As String)
-
-
ChangeFont = "<font face=""" & font & """>" & Value & "</font>"
-
-
End Function
Now, I don't think that I have forgotten any important design details. Let me know if something doesn't work.
@Seth:
Thank you for pointing this important mistake out to me, don't know what I was thinking! The approach that I proposed does in fact work. Instead of directly trying to modify the Font with VBA Code after selecting it, use the Mini Toolbar to change it (requires Access 2007). The Mini Toolbar becomes active after Text has been selected. As an example I used 8 different Fonts for the String listed below in the Text Box named txtRich. The Formatting is also preserved for each individual Record entry. - She Sells Sea Shells by the Sea Shore
Remember that the Text Format property of the Text Box must be set to Rich Text and that its Control Source must be set to a MEMO Field whose Text Format should also be set to Rich Text.
@Adezii That would be the simpler method, but since the OP requested it be done by clicking an option in an option group, I went the VBA route. Also, I don't think that mini toolbar is available in Access Runtime. This wasn't a requirement in the OP, but it was fun to work out the necessary requirements to do it in VBA.
NeoPa 32,556
Expert Mod 16PB
In case no-one caught Z's edit comment, he's pointed out that this is a new option in 2010. i've updated my earlier post to make that clear to anyone coming new to the thread.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: kmunderwood |
last post by:
I am having trouble changing the font size when extracting xml into an
html web page.
I think it can be done so many ways, that my searches bring up examples
that I am not familiar with.
I am a...
|
by: metamedia |
last post by:
How do I get a datagrid to register a data change from a custom control cell (combobox)
I've got a Windows Application with a Windows Form Datagrid that has a custom combobox column. When the user...
|
by: David Dvali |
last post by:
Hello.
I have one TextBox and one CheckBox on my web page, now when I click on the
CheckBox I want to change font (depends on CheckBox state) of my TextBox
wuth JavaScript.
How can I do this?
...
|
by: Jane Sharpe |
last post by:
Hi,
I have a textbox with the words "Enter your name here" inserted as default
text - At the moment, to remove this the user must highlight all the text
and delete before they type in their name...
|
by: Adam Honek |
last post by:
I have a form.
It has serveral text boxes for user data entry.
I could of course write code to check if each is empty before proceeding to
save this data to a file.
Is there any global way...
|
by: xntric |
last post by:
Hi,
I have a form with multiple text boxes.
In the text boxes i have grey font with default values to show an example for users.
Is there a way to code the form to automatically change a textbox...
|
by: _Who |
last post by:
I spent all day yesterday trying different things.
Something has happened so I can't change font size.
I have a table and in the first cell I have only text.
I tried using the cell's Style...
|
by: reyo |
last post by:
Hi,
i design a dynamic web page.infact it will be a css generator.
i have a question about visited link.
i want to change color,font-size,font-weight etc. of a link when it is visited.
when a...
|
by: starrj |
last post by:
I am using VB.NET VS2010
This seems like a trivial problem but I am unable to get past it. I have a very simple custom textbox class (full code below) that draws a rounded corner border around the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
| |