Changing properties with a function

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Hi all,

I'm trying to change the colour and special effect of a rectangle
through a function because I want to have stop and go lights and I
want to be changing them frequently, so my function is like this:


Public Function SwitchOn (BoxName) as String

Form_Home.BoxName.BackColor.Value = 4634122
Form_Home.BoxName.SpecialEffect.Value = "Sunken"

end function

then I call it by using:

switchon (box1) - also tried switchon ("box1")

but it doesn't want to work at all... how do I get the damn thing to
work???? Do I have to set BoxName as a Rectangle or an Object instead
of a string?

Please help!

Cheers,

Bob
 
Bob,

If you only want to change one rectangle as you are describing in your code,
try changing the declaration line of your function to:
Public Function SwitchOn (BoxName as String)

Then call the function with:
switchon ("box1")

If you wanted to have more that one light, here is a function that will work
for three lights: Stop, Caution and Go

This function assumes that there are three boxes on the form each box has
the following properties set in design mode:
Back Style = Normal
Back Color = -2147483633

Here is the function:

Select Case strCtrlName
Case "bxStop"
With Me.bxStop
.BackColor = 255
.SpecialEffect = 2
End With
With Me.bxCaution
.BackColor = -2147483633
.SpecialEffect = 0
End With
With Me.bxGo
.BackColor = -2147483633
.SpecialEffect = 0
End With
Case "bxCaution"
With Me.bxCaution
.BackColor = 65535
.SpecialEffect = 2
End With
With Me.bxStop
.BackColor = -2147483633
.SpecialEffect = 0
End With
With Me.bxGo
.BackColor = -2147483633
.SpecialEffect = 0
End With
Case "bxGo"
With Me.bxGo
.BackColor = 65280
.SpecialEffect = 2
End With
With Me.bxStop
.BackColor = -2147483633
.SpecialEffect = 0
End With
With Me.bxCaution
.BackColor = -2147483633
.SpecialEffect = 0
End With
End Select
End Function

You would call the function from the Click event of each button with:
SetLights ("Name of Each Button")
 
Assuming the function is in the class module associated with the form, use

Public Function SwitchOn (BoxName As String) as String

Me.Controls(BoxName).BackColor = 4634122
Me.Controls(BoxName).SpecialEffect = acEffectSunken

End Function

You'd call it as SwitchOn("box1")
 
Assuming the function is in the class module associated with the form, use

Public Function SwitchOn (BoxName As String) as String

Me.Controls(BoxName).BackColor = 4634122
Me.Controls(BoxName).SpecialEffect = acEffectSunken

End Function

You'd call it as SwitchOn("box1")

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)














- Show quoted text -

Thanks for your help. It worked a charm - my problem was the
controls(BoxName) part.
 
Back
Top