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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing txt box colors 1

Status
Not open for further replies.

Ben6550

Technical User
Jan 8, 2004
16
GB
I want a text box background to change a different colour when each one of four check boxes are selected within the same form. Does anyone know how to achieve this??
 
Create a sub that will check if all checkboxes are selected and set the background color of the text box accordingly. Then in the click event for each checkbox, call the sub that validates and sets the color. For example:

-----
Code:
Private Sub chkOne_Click()
    
    ColorTextBox

End Sub

Private Sub chkTwo_Click()

    ColorTextBox

End Sub

Private Sub chkThree_Click()

    ColorTextBox

End Sub

Private Sub chkFour_Click()

    ColorTextBox

End Sub

Private Sub ColorTextBox()

    If chkOne And chkTwo And chkThree And chkFour Then
        txtMyTextBox.BackColor = vbRed
    Else
        txtMyTextBox.BackColor = vbWhite
    End If

End Sub
-----

Hope this helps.

- Glen

Know thy data.
 
I use Access 97. Checkboxes do not have a click event.
Which also raises the question: how *do* you use the value of an unbound checkbox on a form?

if chkThing.value ... causes an error
if chkThing ...causes an error, so the example code above

If chkOne And chkTwo And chkThree And chkFour Then

won't work for me either.
 
You can use conditional Formating. In either design or form mode, click the formatting menu item, then conditional formating.
Enter you expression. chkOne.value = True...the rest should be self explanatory.

VBA wise, to reference check boxes it's simply
On the AfterUpdate event or Click event (I'm quite sure both theses events are available Access 2000 & up)
If Me.chkName.value = True Then
chkName.BackColour = vbRed
Else
chkName.BackColour = vbBlack
End If...
..but to be honest with you, I don't believe check boxes have a backcolor property, actually, I'm quite sure they don't.
 
Hi Ben6550,

In my Access 97, Checkboxes have a Click Event and can be referenced.

What error are you getting? If it's "Invalid use of Null", it's simply because the Checkbox hasn't got a value (yet).

dboulos

Conditional Formatting does not exist pre-2000.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Hi TonyJollans,

>>In my Access 97, Checkboxes have a Click Event and can be referenced.
<<

Now we are into XFILES country..

I'm using Access 97. Help screen says SR2

Check box events available:
GotFocus,LostFocus,mouseUp/Down/Move, Keyup/down/press

Thats all..

Error message given by:

If me.chkThing then msgbox &quot;Hello&quot; is
&quot;object required&quot;

me.chKthing.value gives &quot;object required&quot;.
So does me.chkThing.value = 1
so does me.chkthing.setfocus

So, what class/dll provides your checkboxes?
 
Hi JeffTullin,

I have A97 SR-1 and I'm just using standard Checkboxes off the toolbox in form design. I can't find a reference in Help that list events by control type but under Event Properties and Objects They Apply To it includes ..

OnClick* Forms. Form sections. Controls (bound object frame, chart, check box, combo box, command button, image, label, list box, option button, option group, rectangle, tab, text box, toggle button, unbound object frame) on a form.

.. and ..

* These properties don't apply to check boxes, option buttons, or toggle buttons in an option group. They apply only to the option group itself.


In the Form's Class module, if I select a checkbox, Click is the default event out of a long list, but ..

If I have a checkbox in an option group, the listed events are those you quote.

I couldn't get the error you get, but are you using checkboxes in an option group, or stand-alone?

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Thanks TonyJollans

Ah. Pennies drop.
I have used the group boxes in Access just as I do in VB - as a visual nicety to define functional areas.
I have indeed been placing the checkbox in an option group, - always,it appears!

Bing!! - outside of the group, back comes the click event.

Well well well...
 
Gentlemen, I'd like to be able to use this feature, but I can't tell by the end of the correspondence whether you've jointly found a way to make it work or not? Help!
 
Hi kupe,

Yes, we got a bit off topic and Ben6550 (the original poster) has not come back.

Yes, it is possible to change the background colour of a textbox but there are various issues. Can you give a bit more detail - is your field bound or unbound? - do you have a single form or continuous? - are you using A2K (or later) or A97?

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top