AnsweredAssumed Answered

Passing object by Value

Question asked by Jaya on Jan 19, 2017
Latest reply on Jan 24, 2017 by Jaya

Hi

 

I use the below code for formatting a bunch of command buttons.

 

Private Sub fmtCmdBtn(ByVal obj As commandbutton, msg As String,  fillcolor, txtcolor As Double)

    With obj

        .Caption = msg

        .BackColor = fillcolor

        .ForeColor = txtcolor

     End With

End Sub

 

There are no errors when I use :

fmtCmdBtn  btnTest1  "Test"  Vbred,  vbwhite '         where btnTest1 is the name of the command button

 

However, I get a Type Mismatch error when I substitute a variable for the object.

 

Dim myobj as Object  ' Tried  Symbol also with same error

 

Set myobj = ThisDisplay.Symbols.Item(6)

or

Set myobj= ThisDisplay.Symbols("btnTest1")

 

fmtCmdBtn  myobj  "Test"  Vbred,  vbwhite

 

Substituting the name of the button with a variable throws up Type mismatch error. What am I doing wrong? Any help appreciated. Thanks in advance.

Outcomes