title: Assign code to a button created dynamically
body: <p>I'm trying to get a button I've created dynamically on an excel userform form to run a macro called <code>transfer</code> which I've written in <code>Module 1</code> of the "Modules" section of my project.</p>
  
  <p>Below I've pasted the code I've written so far in the userform which actually manages to create the <code>Transfer to Sheet</code> button in the frame (<em>which I've also created dynamically</em>) but for some reason, when I run VBA I get a <code>438 error</code> message saying that <code>Object doesn't support this property or method</code>.</p>
  
  <p>Can anybody tell me how I can resolve this?</p>
  
  <p>Here's the code:</p>
  
  <pre><code>Dim framecontrol1 As Control
  
  Set workitemframe = Controls.Add("Forms.Frame.1")
  With workitemframe
      .Width = 400
      .Height = 400
      .Top = 160
      .Left = 2
      .ZOrder (1)
      .Visible = True
  End With
  
  workitemframe.Caption = "Test"
  Set framecontrol1 = workitemframe.Controls.Add("Forms.commandbutton.1")
  
  With framecontrol1
      .Width = 100
      .Top = 70
      .Left = 10
      .ZOrder (1)
      .Visible = True
      .Caption = "Transfer to Sheet"
  End With
  framecontrol1.OnAction = "transfer"
  </code></pre>