Home > other >  How can I change ActiveControl properties using vba Access?
How can I change ActiveControl properties using vba Access?

Time:04-25

I have created this sub to do some formatting depending on ActiveControl CommandButton

Sub ReFormat(Sender As CommandButton)
    'Me.PictureBox.Picture = Me.Controls(Sender).Picture
    Me.PictureBox.Picture = Sender.Picture
    Me.lbl.Caption = Sender.Caption
    Sender.PictureCaptionArrangement = acRight
    Sender.FontBold = True
    Sender.ForeColor = RGB(45, 48, 60)
End Sub

And called it from :

Private Sub Command0_Click()
    ReFormat (ActiveControl)
End Sub

It throws this error

enter image description here

I tried this

Sub ReFormat(Sender As Object)
Sub ReFormat(Sender As Control)

Still the same .

What am I doing wrong ?

CodePudding user response:

The parenthesis makes it read-only. Try:

ReFormat ActiveControl
  • Related