Setting fore- backcolor ??

ksor

Registered User.
Local time
Yesterday, 19:27
Joined
Feb 8, 2018
Messages
70
I have this generel sub to flashing of a control on a form ,,, flash in a specific color:


Code:
Sub FlashCtrl(OnOff As Boolean, frm As Form, Ctl As Control, Optional flashColor As Long)
    If OnOff = False Then
        frm.TimerInterval = 0
        frm.Controls(Ctl.Name).Visible = False
    Else
        If Not ((frm.Controls(Ctl.Name).ControlType = acTextBox) _
                Or (frm.Controls(Ctl.Name).ControlType = acCommandButton) _
                Or (frm.Controls(Ctl.Name).ControlType = acLabel)) Then Exit Sub
        With Ctl
            ' Here the flashColor should be defined
            .Forecolor   <<<<<<<<<<<<<<<<<<<<<<<<<<<<< NO Forecolor !!
            .Visible = True
        End With
        frm.TimerInterval = 500
    End If
End Sub


but there is NO Forecolor property !


How do I do that ?
 
some controls do not have a forecolor (rectangles, check boxes, web control to name a few), so since ctl can be any control, forecolor won't be selected via intellisense.

If you defined ctl as a textbox or another control that has a forecolor then forecolor would appear as an option

Suggest complete your line and see if it works
 
you haven't designated one.
you can set a default for your optional argument in red below and you'll have to use the variable in your code = flashColor

Code:
Sub FlashCtrl(OnOff As Boolean, frm As Form, Ctl As Control, Optional flashColor As Long [COLOR="Red"]= vbRed[/COLOR])
    If OnOff = False Then
        frm.TimerInterval = 0
        frm.Controls(Ctl.Name).Visible = False
    Else
        If Not ((frm.Controls(Ctl.Name).ControlType = acTextBox) _
                Or (frm.Controls(Ctl.Name).ControlType = acCommandButton) _
                Or (frm.Controls(Ctl.Name).ControlType = acLabel)) Then Exit Sub
        With Ctl
            ' Here the flashColor should be defined
            .Forecolor [COLOR="Red"] = flashColor[/COLOR]
            .Visible = True
        End With
        frm.TimerInterval = 500
    End If
End Sub

but th

If your passing a control as an object I dont think you need to use the form controls collection.
you can just use ctl.ControlType, etc.
 
Last edited:
THX moke123 !


EDIT: No, that wil not work - there IS no .ForeColor property avaiable
 
What type controls are you trying to use?
 
I'm using Office 365 and a Label right now but plan to also use buttons and Textboxes
 
Last edited:
It WORKs if I just type the



.ForeColor = FlashColor


so ... just do it and it works !


Thx to all of you
 
It WORKs if I just type the

.ForeColor = FlashColor

so ... just do it and it works !

Thx to all of you
Hi. Pardon me for jumping in, but I view Intellisense as a guide more than a rule. It's supposed to be just a helper.
 
If this code is supposed to make the control flash you will need code in the timer event also.

you dont need to pass the form if your passing the control as an object.
you can use
Ctl.Parent.TimerInterval = 0 'this refers to the controls parent ie. the form
Ctl.ControlType = acTextBox
Ctl.Visible = True

Code:
Sub FlashCtrl(OnOff As Boolean, Ctl As Control)

    If OnOff = False Then

        Ctl.Parent.TimerInterval = 0
        Ctl.Visible = False
    Else
        If Ctl.ControlType = acTextBox _
           Or Ctl.ControlType = acCommandButton _
           Or Ctl.ControlType = acLabel Then

            Ctl.Visible = True

            Ctl.Parent.TimerInterval = 500

        End If
    End If

End Sub
 
@John: must admit, beginning to think I was being ignored. Doesn't encourage me to respond to the OP in the future:banghead:
 
CJL
Having made suggestions both here & at AccessForums.net, I know how you feel :(
 
As DBG alluded to, I do not take intellisense as gospel. Had no idea on how to convey this to the OP but then CJL put it so eloquently.

I have much to learn...
 

Users who are viewing this thread

Back
Top Bottom