473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

select a part of textbox data and change font of this part not all textbox value

5
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
Jan 28 '14 #1
10 5635
Seth Schrock
2,965 Expert 2GB
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.?
Jan 28 '14 #2
honar
5
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
Feb 2 '14 #3
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.
Feb 3 '14 #4
ADezii
8,834 Expert 8TB
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.
  1. Create a Text Box on a Form and name it txtRich.
  2. 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.
  3. In the Table containing this MEMO Field set its Text Format Property to Rich Text.
  4. Open the Form and select any number of Characters in the txtRich Field.
  5. You can now modify the Font Characteristics of the Selected Text only, as in:
    Expand|Select|Wrap|Line Numbers
    1. Me![txtRich].FontName = "Courier"
  6. Only the Font of the Selected Text will change to Courier.
  7. Any questions feel free to ask.
Feb 3 '14 #5
Seth Schrock
2,965 Expert 2GB
@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).
Feb 3 '14 #6
Seth Schrock
2,965 Expert 2GB
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.
Expand|Select|Wrap|Line Numbers
  1. Private Enum ssFont
  2.     ssTimes = 1
  3.     ssArial = 2
  4.     ssCour = 3
  5. End Enum
  6.  
  7. Private intStart As Integer
  8. Private intLength As Integer
In the textbox's MouseUp event, you need the following code.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtRichText_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.  
  3.     intStart = Me.txtRichText.SelStart
  4.     intLength = Me.txtRichText.SelLength
  5.  
  6. End Sub
Next, I have the Option Group AfterUpdate event along with a custom function.
Expand|Select|Wrap|Line Numbers
  1. Private Sub optFont_AfterUpdate()
  2.     Dim strTextbox As String
  3.     Dim strBef As String
  4.     Dim strSel As String
  5.     Dim strAft As String
  6.     Dim font As String
  7.  
  8.     strTextbox = PlainText(Me.txtRichText)
  9.  
  10.     strSel = Mid(strTextbox, intStart + 1, intLength)
  11.     strBef = Left(strTextbox, intStart)
  12.     strAft = Mid(strTextbox, intStart + intLength + 1)
  13.  
  14.     Debug.Print strBef, strSel, strAft
  15.  
  16.     Select Case Me.optFont
  17.         Case ssTimes
  18.             font = "Times New Roman"
  19.  
  20.         Case ssArial
  21.             font = "Arial"
  22.  
  23.         Case ssCour
  24.             font = "Courier New"
  25.  
  26.     End Select
  27.  
  28.     Me.txtRichText = "<div>" & strBef & ChangeFont(strSel, font) & strAft & "</div>"
  29.  
  30. End Sub
  31.  
  32. Private Function ChangeFont(Value As String, font As String)
  33.  
  34.     ChangeFont = "<font face=""" & font & """>" & Value & "</font>"
  35.  
  36. End Function
Now, I don't think that I have forgotten any important design details. Let me know if something doesn't work.
Feb 3 '14 #7
ADezii
8,834 Expert 8TB
@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.
Expand|Select|Wrap|Line Numbers
  1. 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.
Feb 3 '14 #8
Seth Schrock
2,965 Expert 2GB
@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.
Feb 3 '14 #9
ADezii
8,834 Expert 8TB
@Seth:
All good points.
Feb 3 '14 #10
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.
Feb 4 '14 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
0
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...
1
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? ...
10
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...
2
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...
2
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...
5
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...
3
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...
0
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.