OnClick and OnDblClick

azmirnordin

Registered User.
Local time
Today, 18:31
Joined
Jan 3, 2011
Messages
57
Hi Guys.. :D

I wanna change the particular cell backcolor colour for each record that I selected. As an example if the column name CarNo I put the OnClick event like below

Private Sub CarNo_Click()
ClrRed as Long
ClrRed = RGB(255,0,0)
CarNo.BackColor = ClrRed
End Sub

This works. But how do I maintain the color Red in that particular cell ? The color back to default as I click the next or other cell.
The other thing I wanna do is If on 1st click the cell goes Red, then when I click the same cell again, its color back to default. Is there any way that I can keep the previous and new colour number, let say 0 for default and 1 for red in table for later use?

In Summary
**********
1st Click = cell color turn red
2nd Click = cell color change from red to default

AnyIdea is appreciate..

Cheers :)
 
Hi
I ones solved a similar problem and created the following procedure for it.
May you can solve your problem with it as well good luck and have fun

Function changeconT(strform, strsubform, strcontrol, strprop As String, strvalue As Variant)
'SETS THE PROPERTIES OF A CONTROL ON A DESIGNATED SHEET

'strform = "Projectview" name of the sheet
'strsubform = "child1" name of the child sheet"N" means no subform
'strcontrol = "LabelIt7" name of the control
'strprop = "backColor" 'name of the functio to set
'strvalue = 16777215 'value of the function to adapt

Dim frm As Form
Dim frmS As SubForm
Dim ctl As Control

If strsubform = "N" Then
'not on a subform
Set frm = Forms(strform)
Set ctl = frm.Controls(strcontrol)
Else
'on a subform
Set frm = Forms(strform)
Set frmS = frm.Form(strsubform)
Set ctl = frmS.Controls(strcontrol)
End If

'set the property
ctl.Properties(strprop).Value = strvalue
End Function
 
to toggle a color, you need this sort of logic

if control.backcolor = vbred
then control.backcolor = someothercolour
else
control.backcolor = vbred


however to change the colour as you navigate from control to control - you really need to be using the gotfocus/lostfocus events for each control
 
Hi Guys,
Thank for the Reply.
My color code doesnt work out.
I try to use .backColor = vbRed and .backColor = clrRed , which clrRed = RGB(250,0,0) but both failed!

Confused :confused:
 

Users who are viewing this thread

Back
Top Bottom