promotion image of download ymail app
Promoted

In Outlook VBA how do I access a form's control's property?

In Outlook 365 I have a simple user form (UserForm1) with a single command button control (CB1). In the CB1_Click() subroutine I want to read any of the control's properties - I have chosen Caption.

I have tried many variations of the syntax and am quite prepared to admit that I can't see what is happening. Can you enlighten me? If you can explain how the correct syntax works too that would help me in the future. When I run the code below I get run-time error 424: Object required.

Private Sub CB1_Click()

Dim mystr As String

mystr = Forms!Form("UserForm1").Controls("CB1").Caption

MsgBox mystr

End Sub

Thanks for your time,

Phil M.

1 Answer

Relevance
  • 1 month ago

    I have solved it.  As usual I was trying to be too clever, much too clever.  The simple and neat solution is:

        mystr = UserForm1.CB1.Caption

    TTFN,

      Phil M.

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.