Help with backcolor

  • Thread starter Thread starter Froto
  • Start date Start date
F

Froto

It's me again. I tried the help that tina gave.

Private Sub SetBackColor(ByVal ctlBox As Control)

If Screen.ActiveControl = True Then
ctlBox.BackColor = 255
Else
ctlBox.BackColor = 16777215
End If

End Sub

on each checkbox's AfterUpdate event, add the following
procedure, as

Private Sub YourCheckBox_AfterUpdate()

SetBackColor Me!YourSquareControlName

End Sub


It works but the problem is when I close the database and
reopen it, the backcolor is gone so the real problem is
how do I get the textbox to retain the backcolor after
database is closed.
 
-----Original Message-----

It's me again. I tried the help that tina gave.

Private Sub SetBackColor(ByVal ctlBox As Control)

If Screen.ActiveControl = True Then
ctlBox.BackColor = 255
Else
ctlBox.BackColor = 16777215
End If

End Sub




on each checkbox's AfterUpdate event, add the following
procedure, as

Private Sub YourCheckBox_AfterUpdate()

SetBackColor Me!YourSquareControlName

End Sub


It works but the problem is when I close the database and
reopen it, the backcolor is gone so the real problem is
how do I get the textbox to retain the backcolor after
database is closed.
.


OK Frodo, try this. First go to each of the Text boxes and
put either vbRed or vbWhite in the Tag field under the
Other list of properties. This is a place that lets you
store values for future use.
Then
Put this code in the On Load event of the form and make
sure to change YourFormName to the name of the form you
are using.
Dim ctl As Control
Dim frm As Form
Set frm = Forms!YourFormName
For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox
if ctl.tag = "vbRed" then
ctl.BackColor = vbRed
else
ctl.BackColor = vbWhite
end if
End Select
Next
Set frm = Nothing
Then put this code in the On DoubleClick event of all the
text boxes:

If Me.Tag = "vbRed" Then
Me.Tag = "VbWhite"
Me.txtColor.BackColor = vbWhite

Else
Me.Tag = "Vbred"
Me.txtColor.BackColor = vbRed
End If

That should do it.

The last bit could be made into a function and have the
Text name passed to it but I don't have time to tell you
how to do that. Good Luck
 
here's a solution; to use it you'll have to utilize the "Tag" property after
all.
add the "square" control's name to the corresponding checkbox's Tag
property, as

YourSquareControlName

type it just as you see it above, no equal sign or quotes, and no form
reference. (in my test db, the first "square" is named Text1, and the
checkbox in its' middle is Check5. so the Check5 control's Tag property is
Text1.)

add the following code to the form's OnCurrent event, as

Private Sub Form_Current()

Dim Ctl As Control, strSquare As String

For Each Ctl In Me.Controls
If Ctl.ControlType = acCheckBox Then
strSquare = Ctl.Tag
If Nz(Ctl, False) Then
Me(strSquare).BackColor = 255
Else
Me(strSquare).BackColor = 16777215
End If
End If
Next

End Sub

btw, it's best to *not* start a new thread on the same issue, unless you're
posting after maybe a day's lapse of time, or more. most of us check our
previously posted answers periodically, to answer additional questions - or
to read additional solutions /viewpoints from other people who also posted
answers/comments.
starting a new thread (or multiple new threads, as you did today) can be
very confusing, because many people won't relate a new thread to previous
ones - you end up hoeing the same row again and again. and it's frustrating
to someone who takes the time to post an answer to one thread, and later
sees that you started a new one - apparently without reading their response
to your previous thread.

hth
 
Back
Top