Color Text Box

C

channell

I have a check box and a text box. How to I make it so when my check box is
checked (or=Yes), my text box is yellow? Thank you very much!

-Scott Channell
 
S

Stefan Hoffmann

hi Scott,
I have a check box and a text box. How to I make it so when my check box is
checked (or=Yes), my text box is yellow? Thank you very much!
Use the after update event of your check box:

Private Sub CheckBox0_AfterUpdate()

If CheckBox0.Value Then
Text0.BackColor = RGB(255, 0, 255)
Else
Text0.BackColor = RGB(255, 255, 255)
End If

End Sub



mfG
--> stefan <--
 
C

channell

This is what I have, but it is not displaying the color when it is checked:
What am I doing wrong?

Private Sub SUSPENSION_CHECK_AfterUpdate()

If SUSPENSION_CHECK = Yes Then
OCCURANCE_DATE.BackColor = RGB(255, 0, 255)
Else
OCCURANCE_DATE.BackColor = RGB(255, 255, 255)
End If

End Sub


Thanks again Stefan.
 
S

Stefan Hoffmann

hi,
This is what I have, but it is not displaying the color when it is checked:
What am I doing wrong?
Please compare my example and your piece of code line by line, then you
will find a difference in the If-condition...


mfG
--> stefan <--
 
C

channell

I apologize for not posting that I also tried this, but I am still getting no
response from the text box. I appreciate you helping to look closer, as I
know very little about VBA Coding, and I am eager to learn it. Thanks again
Stefan.

Private Sub SUSPENSION_CHECK_AfterUpdate()
If SUSPENSION_CHECK.Value Then
[OCCURANCE DATE].BackColor = RGB(255, 0, 255)
Else
[OCCURANCE DATE].BackColor = RGB(255, 255, 255)
End If

End Sub
 
S

Stefan Hoffmann

hi,
I apologize for not posting that I also tried this, but I am still getting no
response from the text box.
Is the event assigned to the combo box? Open the property editor, select
your check box. Change to page events, In line of After Update must have
the value [Event Procedure].



mfG
--> stefan <--
 
C

channell

Yes, I have everything where it needs to be, and assigned to the right
checkbox... any other ideas as to why it may not be working? Thanks again!

Stefan Hoffmann said:
hi,
I apologize for not posting that I also tried this, but I am still getting no
response from the text box.
Is the event assigned to the combo box? Open the property editor, select
your check box. Change to page events, In line of After Update must have
the value [Event Procedure].



mfG
--> stefan <--
 
D

Dirk Goldgar

channell said:
Yes, I have everything where it needs to be, and assigned to the right
checkbox... any other ideas as to why it may not be working? Thanks
again!

If you're using Access 2007, it's worth verifying that VBA code is not
disabled. In that situation, make sure the database is in a trusted
location, as specified in the Trust Center.
 
C

channell

Here is where I am at- If I use the following code I have two problems:

Private Sub SUSPENSION_CHECK_AfterUpdate()
If [SUSPENSION CHECK].Value Then
[OCCURANCE DATE].BackColor = vbYellow
Else
[OCCURANCE DATE].BackColor = vbWhite
End If

End Sub

1. The all records are highlighted, not just the individual one that is
checked
and
2. If I close the form and open it back up, the fields are no longer
highlighted.

I need the record to stay colored for as long as the check box is marked,
and I only need an individual record marked, not every record. Please Help?

Stefan Hoffmann said:
hi,
I apologize for not posting that I also tried this, but I am still getting no
response from the text box.
Is the event assigned to the combo box? Open the property editor, select
your check box. Change to page events, In line of After Update must have
the value [Event Procedure].



mfG
--> stefan <--
 
C

channell

I'm on office 2003

Dirk Goldgar said:
If you're using Access 2007, it's worth verifying that VBA code is not
disabled. In that situation, make sure the database is in a trusted
location, as specified in the Trust Center.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
B

BruceM

To start I would compile the code (Debug >> Compile) if you have not already
done so.

Just to be sure everything is clear I would give the controls different
names than the fields. For instance, chkSuspensionCheck is the check box
bound to the SuspensionCheck field; txtOccurrenceDate is the text box bound
to OccurrenceDate. That shouldn't matter in this case (I think there are
some cases where it does), but I find it makes the code easier to read.

The other thing I would try is adding Me. in front of control names:

If Me.chkSuspensionCheck Then
etc.

Value is the default property for a control. You can add it if you wish,
but it shouldn't be necessary. As I recall Stefan tends to specify the
default property, which is proably good practice, but I have to admit I tend
not to do that.

BTW, if SuspensionCheck is a yes/no field, the following are equivalent:

If Me.chkSuspensionCheck = True Then ...
If Me.chkSuspensionCheck Then ...

However, I don't think Yes works in place of True.

channell said:
Yes, I have everything where it needs to be, and assigned to the right
checkbox... any other ideas as to why it may not be working? Thanks
again!

Stefan Hoffmann said:
hi,
I apologize for not posting that I also tried this, but I am still
getting no
response from the text box.
Is the event assigned to the combo box? Open the property editor, select
your check box. Change to page events, In line of After Update must have
the value [Event Procedure].



mfG
--> stefan <--
 
J

John Spencer

Use conditional formating.

In design view click on Suspension Check
Select Format: Conditional formatting... from the menu
In the dialog.
Change "Field Value is" to "Expression is"
Enter the following
[Suspension Check] = True
Click the Paint Bucket and Select the background color you want to use
Click OK
TEST.
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Here is where I am at- If I use the following code I have two problems:

Private Sub SUSPENSION_CHECK_AfterUpdate()
If [SUSPENSION CHECK].Value Then
[OCCURANCE DATE].BackColor = vbYellow
Else
[OCCURANCE DATE].BackColor = vbWhite
End If

End Sub

1. The all records are highlighted, not just the individual one that is
checked
and
2. If I close the form and open it back up, the fields are no longer
highlighted.

I need the record to stay colored for as long as the check box is marked,
and I only need an individual record marked, not every record. Please Help?

Stefan Hoffmann said:
hi,
I apologize for not posting that I also tried this, but I am still getting no
response from the text box.
Is the event assigned to the combo box? Open the property editor, select
your check box. Change to page events, In line of After Update must have
the value [Event Procedure].



mfG
--> stefan <--
 
C

channell

THANKS A TON!!! Just what I needed! Ia m always glad to learn something
new. I have now applied this technique to several aspects in my database. I
greatly appreciate it.

-Scott Channell

John Spencer said:
Use conditional formating.

In design view click on Suspension Check
Select Format: Conditional formatting... from the menu
In the dialog.
Change "Field Value is" to "Expression is"
Enter the following
[Suspension Check] = True
Click the Paint Bucket and Select the background color you want to use
Click OK
TEST.
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
Here is where I am at- If I use the following code I have two problems:

Private Sub SUSPENSION_CHECK_AfterUpdate()
If [SUSPENSION CHECK].Value Then
[OCCURANCE DATE].BackColor = vbYellow
Else
[OCCURANCE DATE].BackColor = vbWhite
End If

End Sub

1. The all records are highlighted, not just the individual one that is
checked
and
2. If I close the form and open it back up, the fields are no longer
highlighted.

I need the record to stay colored for as long as the check box is marked,
and I only need an individual record marked, not every record. Please Help?

Stefan Hoffmann said:
hi,

channell wrote:
I apologize for not posting that I also tried this, but I am still getting no
response from the text box.
Is the event assigned to the combo box? Open the property editor, select
your check box. Change to page events, In line of After Update must have
the value [Event Procedure].



mfG
--> stefan <--
 
K

Kevin Hyronemus

I created a database to track my bills and in one table I have the following.

Bill - Text box
1st Payment - Text box
Paid1 - Checkbox
2nd Payment - Text box
Paid2 - Checkbox

I used conditional formating to change the 1st and 2nd payment text boxes green if the amount is less then or equal to 0 and red if its greater than 0.

The first line of the conditional formating is "Expression Is" and the value is "[paid1]=Yes" to change the 1st payment text box green again when the paid1 check box is checked.

This works for the 1st Payment text box, but when I use the same conditional formating for the 2nd Payment box and change the "Expression Is" line to reflect "[paid2]=Yes", the 2nd Payment text box doesn't change colors unless both the paid1 and paid2 check boxes are checked.

I need the 2nd payment to change colors without both checkboxes being checked because sometimes the bills only come out of my second check.

Hopefully this makes sense and any help fixing it is greatly appreciated.

Thanks
Kevin
 
K

Kevin Hyronemus

After further review, when checking the [paid1] checkbox, it turns both the 1st payment and 2nd payment text boxes green.

The [paid2] checkbox does absolutley nothing checked or unchecked
 
K

Kevin Hyronemus

Sorry for the spamming but I figured it out. Apparently I had to rename the 2nd checkbox and everything works now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top