Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Color in a text box 3

Status
Not open for further replies.

SheepDog

Programmer
Feb 4, 2003
232
US
Using this code below for a text box in a report can I make the Name: in red and the First_Name and Last_Name in black?

="Name : " & [FIRST_NAME] & " " & [LAST_NAME]
 
Why do you need to add the label 'Name' to the concatenated string? It would be easy to leave it as a seperate label and only concatenate the name portion, then format as needed.

-Gary
 
Because I have the fields listed horizontally across the top of the page.
I have a first and last name, address, city-state-zip code,
day phone, evening phone, e-mail
Since not every one has the same number of charcaters in all of these fields it was easier to put in the field name in and concatenate it to the data source since the separate label and text box was taking up too much room.
 
Actually.....it would be easiest (and I believe the only way!) to use two text boxes....

The first is a text box and has the label "Name :" attached to it
The second has no label and directly touches the first text box

Finally play with the properties of these two text boxes, such as borderstyle, specialeffect, etc, to make them appear as one box...

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
I like the last idea but do not want top take up too mcu room with separate text boxes and labels.
 
I tried the suggesion of a separate text box/label and then the text box with the field names in them. This takes up way to much room. I know I can get the font to be different colors as I had wanted but can not get all the infomation on the report and in the format that I wanted.
 
sheepdog,

if you can exmplain to me how you can change the format of text inside a text box, I will be happy to help you solve this.....as far as I know, this cannot be done.....only one format style and color is allowed in a text box.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
If you look in the On Print event of the LADY report, you will see the following code:
Code:
            ' Create desired Font settings
            ' for the Last Name - Bold Text
            .FontBold = True
            '.FontItalic = True
            '.ForeColor = RGB(255, 0, 0) 'RED
I would assume you can comment/uncomment out the font attributes you want or don't want.....

Hoc nomen meum verum non est.
 
Okay here is what I want to do. Can it be done with the code in the LADY report?

="Name: " & [FIRST_NAME] & " " & [LAST_NAME]

I want "Name" to be in red font and [FIRST_NAME] and [LAST_NAME] to be in black font
 
I've never used this particular code, but yes, it looks like it can.

Hoc nomen meum verum non est.
 
KosmoKramer: SheepDog wants to mix the colors in a single control. I don't think the code your referred to will do that though. There is a special kind of control type that can be mised text font, bold, colors, etc but I can't remember the name of it. MichaelRed has mentioned it before but it seems like a fairly difficult process.

SheepDog: You say that you are listing your controls horizontally across the page and you are running out of room. I don't understand why you need to have the identifier(i.e. Name) on the same line. Put individual labels in the Page Header above each column of data to identify it. This will save a whole bunch of space for you.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
I did have them in the header. But here is what I have now going on. I have Name-Address-City, State, Zip then on the next line I have Day Phone, Evening Phone, E-mail Address.

My question is that if I have two lines going horizontal with this how do I make the Day, Evening Phone and E-Mail in the header below the Name, Address and City,State,Zip ?
 
You can create two rows of labels. Have the second row a different color to designate a different line and bring attention to it by the user. Line up the left edge of all of your controls with the left edges of the labels. Try to space them out appropriately. If you use the color scheme as I said above, you could have the second line controls have the type color be the same. I think is way easier to read a report without the labels right next to the data. Once a user reads the report one time and sees the two lines of data and you provide a visual way to identy the columns then it is easy. Also, you might way to put a hairline horizontally after the second line. This breaks up the pars easily for reviewing.

Good luck.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
Bob:
I'll give it a try, just wanted to make it more dramatic in what I was trying to do but will end up with your suggestion to make it work.
 
I tried the following code in the LADY database, and it was successful in displaying LastName in red, and FirstName in black, both in the same control:
Code:
With Me
            ' Make sure we are in Twips
            .ScaleMode = TWIPS
                                
            ' Grab Controls current Font settings
            .FontName = CtlDetail.FontName
            .fontsize = CtlDetail.fontsize
                                    
            ' Create desired Font settings
            ' for the Last Name - Bold Text
            '.FontBold = True
            '.FontItalic = True
            [COLOR=red].ForeColor = RGB(255, 0, 0) 'RED[/color]
            .CurrentX = CtlDetail.Left
            .CurrentY = CtlDetail.Top
            ' For some reason must be Me.Print not .Print
            Me.Print strLast;
            Me.Print ", ";
            
            ' Reset Font-> NO Bold for FirstName
            [COLOR=red].ForeColor = vbBlack[/color]
            '.FontBold = False
            '.FontItalic = False
            Me.Print strFirst

Hoc nomen meum verum non est.
 
Cosmo:
My question is can you change the font color in something other than the field name?

="Name: " & [First_Name] & " " & [Last_Name]

What I mean is can you change "Name:" to red font since it is not a field name and [First_Name] and [Last_Name] to black font.
 
My apologies Kosmo. You are correct. I misread this and am appreciative of you following up. Star for you.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
SheepDog: After reviewing the code in the Lady.mdb software that CosmoKramer has pointed you to the answer to your question is yes you can modify any of the characters to any of the settings that you need. It just requires the parsing of the three different section of the controls string: "Name: ", [FirstName], and [LastName]. I have modified the code to demo this for you.

Given a control with the following Control Source property:
Code:
="Name:  " & [First_Name] & " " & [Last_Name]

This code taken from the database Lady.mdb written by Steven Lebans and modified for your controls format. Any of the font, size, color, underline, etc. attributes can be modified within a control. Just remember that you must set them first before you perform the Me.Print string and then reset them for the printing of the next string. The code will then set the attributes back to their original settings after printing each control.

Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)

Const TWIPS = 1
Dim strLabel As String
Dim strFirst As String
Dim strLast As String
Dim intPosition As Integer
Dim CtlDetail As Control
Dim intMargin As Integer

' I'll leave in Italic and Color
' in case you want to use these
Dim oldFontBold As Integer
Dim oldFontItalic As Integer
Dim oldFontUnderline As Integer
Dim oldForeColor As Long
Dim oldFontName As String
Dim oldfontsize As Integer
Dim oldScaleMode As Integer

'Save current Font settings
With Me
    oldFontItalic = .FontItalic
    oldFontBold = .FontBold
    oldForeColor = .ForeColor
    oldFontUnderline = .FontUnderline
    oldFontName = .FontName
    oldfontsize = .fontsize
    
    oldScaleMode = .ScaleMode
End With

' Set Margin for Border we will draw
' around your concatenated control.
intMargin = 60
      
For Each CtlDetail In Me.Section(acDetail).Controls
    If CtlDetail.name = "[red][i]yourcontrolname[/i][/red]" Then
        With CtlDetail
            .Visible = False
            intPosition = InStr(InStr(1, .Value, ":") + 2, .Value, " ")
            strLabel = Left(.Value, InStr(1, .Value, ":"))
            strFirst = Mid$(.Value, InStr(1, .Value, ":") + 2, Len(.Value) - intPosition)
            strLast = Mid(.Value, intPosition + 1)            
        End With
        
        With Me
            ' Make sure we are in Twips
            .ScaleMode = TWIPS
                                
            ' Grab Controls current Font settings
            .FontName = CtlDetail.FontName
            .fontsize = CtlDetail.fontsize
            .CurrentX = CtlDetail.Left
            .CurrentY = CtlDetail.Top
            'create desired Font settings
            'for the label Name:
            .ForeColor = RGB(255, 0, 0) 'RED
            .CurrentX = CtlDetail.Left
            .CurrentY = CtlDetail.Top
            Me.Print strLabel;
            ' Create desired Font settings
            ' for the First Name
            .ForeColor = RGB(0, 0, 0) 'Black
            Me.Print strFirst;
            Me.Print " ";
            Me.Print strLast

' Restore Reports original Font settings
.ScaleMode = oldScaleMode
.FontBold = oldFontBold
.FontItalic = oldFontItalic
.FontUnderline = oldFontUnderline
.FontName = oldFontName
.fontsize = oldfontsize
.ForeColor = oldForeColor

End With
                                               
        With CtlDetail
         'While we are here lets draw a box around each field
         Me.Line ((.Left - intMargin), (.Top - intMargin))-Step((.Width + (intMargin * 2)), (.Height + (intMargin * 2))), 0, B
        End With
    End If
Next

' Cleanup
Set CtlDetail = Nothing
End Sub

Post back if you have any more questions.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top