You can change the text font color within the textbox but it will be global to all text within that box (Me.myTextBoxName.ForeColor = vbRed). if you want to make only certain sections or words of a Textbox contain a different font color then you will need to use the Rich TextBox Control.
I've looked into the rich textbox control and still do not see how I would change the color of highlighted text within that control. The color buttons on the toolbar are grayed out when I'm in this control.
Please send help.
First you need to have a means to select a specific color and the best way to do this is by using the Color Dialog Box. The code needed to do this is shown below. Place this code into a new database code module (which would be located in the modules section of your database window) and name it ColorDialog. You could create your own color unit but for now, it's easier to just use the system dialog.
'Color Dialog Box
Private Type COLORSTRUC
lStructSize As Long
hwnd As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
Flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
Private Const CC_SOLIDCOLOR = &H80
Private Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" _
(pChoosecolor As COLORSTRUC) As Long
Public Function GetDialogColor() As Long
Dim X As Long, CS As COLORSTRUC, CustColor(16) As Long
CS.lStructSize = Len(CS)
CS.hwnd = hWndAccessApp
CS.Flags = CC_SOLIDCOLOR
CS.lpCustColors = String$(16 * 4, 0)
X = ChooseColor(CS)
If X = 0 Then GetDialogColor = 0: Exit Function
GetDialogColor = CS.rgbResult
Because your selected color is in Access Long numerical format (i.e.: white = 16777215), for your color to work in Rich Text Format (RTF), it must be provided in a RGB format therefore a conversion is required. To make this conversion I have provided a small Sub procedure which will break down the Long number (i.e.: 16777215) into its' respective RGB components (i.e.: R = 255, G = 255, B = 255).
Public Sub LngToRGB(L_RGB() As Integer)
'Open the Color Dialog Box and Convert Access Long
'colors to RGB colors.
'You must pass the predefined variable array L_RGB()
'to this procedure.
Dim SelectedColor As Long
'Open the COLOR dialog box and place the selected color
'into the SelectedColor variable.
SelectedColor = GetDialogColor
'Convert to RGB.
L_RGB(0) = SelectedColor And &HFF& 'Red
L_RGB(1) = (SelectedColor And &HFF00&) / 2 ^ 8 'Green
L_RGB(2) = (SelectedColor And &HFF0000) / 2 ^ 16 'Blue
And this is how you would use this Sub Procedure:
Dim L_RGB(0 To 2) As Integer 'You must Have This Array...
MsgBox "The RGB (Red, Green, Blue) equivalent of the " & _
"color selected is: " & vbNewLine & vbNewLine & _
" R = " & L_RGB(0) & vbNewLine & _
" G = " & L_RGB(1) & vbNewLine & _
" B = " & L_RGB(2)