Changing text color in unbound text box (1 Viewer)

pp8082

Registered User.
Local time
Today, 08:30
Joined
Jan 27, 2013
Messages
29
Is it possible to change the color of a data filed in a form based on its valu?e

I execute the following when the command button is clicked.
docmd.openforms "inventory"

if a field is less than 0 I'd like to display it as red otherwise display as green.

Is this possible?
 

GanzPopp

Registered User.
Local time
Today, 17:30
Joined
Jan 14, 2013
Messages
37
Right-click on the text box and select 'Conditional Formatting...'
 

pp8082

Registered User.
Local time
Today, 08:30
Joined
Jan 27, 2013
Messages
29
GanzPopp,
Thanks for responding.
I new to this, you could please be more specific?
Where do I put this code? Aslo please give me an example as to how it would be written.
Thanks.
 

GanzPopp

Registered User.
Local time
Today, 17:30
Joined
Jan 14, 2013
Messages
37
Access 2000 does not properly support conditional formatting unfortunately. You can do this partially by using VBA code:
-Open the form properties dialog
-Go to event and create a code event for 'On Current'
-Insert the following code in your VBA window in the newly created procedure:
Code:
With TextBox
    If .Value >5 Then
        .BackColor = 255
        .ForeColor = 0
    Else
        .BackColor=0
        .ForeColor=255
    End If
End With
-Replace 'TextBox' by the name of your text box and the other values by the ones you want

Of course, this will only adjust the colors of your text box in the current record.

To achieve this for the whole form at the same time, upgrade to a newer version of Access. This is highly recommendable, because the newer version have a lot more functionality and lots of stupid bugs have been fixed.
 

pp8082

Registered User.
Local time
Today, 08:30
Joined
Jan 27, 2013
Messages
29
My mistake, but it is not a text box that I want to change, but the field on the form is a data field . How would the with statement work with a data field.

Thanks,
 

GanzPopp

Registered User.
Local time
Today, 17:30
Joined
Jan 14, 2013
Messages
37
How do you display the value of the data field on the form? Do you use a text box, or something else? Maybe I don't understand instead.
 

pp8082

Registered User.
Local time
Today, 08:30
Joined
Jan 27, 2013
Messages
29
The process is as follows: Click on a command buttom and display a form with the last record on the database.

The code is:

I click on a command button, it executes the following procedure:

Private Sub Command11_Click()
DoCmd.OpenForm "currentbuysell"
End Sub

The on load event for the form "currentbuysell" has
the following procedure on it

Private Sub Form_Load() ' this gets last record in table

If Not Me.NewRecord Then
RunCommand acCmdRecordsGoToLast
End If


End Sub
 

GanzPopp

Registered User.
Local time
Today, 17:30
Joined
Jan 14, 2013
Messages
37
Yes, I understand, but this still doesn't tell me how you display the value, or in what type of control the value is displayed.

If you open the properties window of the control it is displayed in, Access will mention the type of control in the first line.
 

pp8082

Registered User.
Local time
Today, 08:30
Joined
Jan 27, 2013
Messages
29
Click on properties the following is displayed.
Text Box: BuyOrSell
Under All Tab
Name : BuyOrSell
Control Source : BuyOrSell

Under Data Tab
Control Source: BuyOrSell
 

GanzPopp

Registered User.
Local time
Today, 17:30
Joined
Jan 14, 2013
Messages
37
OK, so you are using a text box to display the data. We are talking about the same thing here. Hence, my code above still works.

Replace 'TextBox' with 'BuyOrSell' and see if you can get it working.
 

pp8082

Registered User.
Local time
Today, 08:30
Joined
Jan 27, 2013
Messages
29
Ganz,

You are right. I changed the logic and it works.
One more favor. What are the color number for yellow and green ?

Thanks so much
 

Users who are viewing this thread

Top Bottom