title: Defining object part in callbyname function with variables
body: <p>I am facing a problem when I want to rewrite part of my program. This part is put in module1 and look like as follows:</p>
  
  <pre><code>Public Function InputCorr(Target As MSForms.Control) As Boolean
  
      If FrmAddRecord1Shown Then
          Target.Value = CallByName(frmAddRecord1, Target.Name &amp; "_Min", VbMethod)
      ElseIf FrmAddRecord2Shown Then
          Target.Value = CallByName(frmAddRecord2, Target.Name &amp; "_Min", VbMethod)
      End If
  
  End Function
  </code></pre>
  
  <p>And I am going to rewrite like this:</p>
  
  <pre><code>Public Function InputCorr(Target As MSForms.Control) As Boolean
  
      Dim UF As UserForm
  
      If FrmAddRecord1Shown Then
          set UF = frmAddRecord1
      ElseIf FrmAddRecord2Shown Then
          set UF = frmAddRecord2
      EndIf 
  
      Target.Value = CallByName(UF, Target.Name &amp; "_Min", VbMethod)
  
  End Function
  </code></pre>
  
  <p>FrmAddRecord1Shown and FrmAddRecord2Shown are boolean, indicating which userform (frmAddRecord1 or frmAddRecord2)is active.</p>
  
  <p>However, "run-time error"438": Object doesn't spport this property or method" occurs. I believe I was stuck at the "UF" defining part. Is it possible for me to define the "object" part of "callbyname" function with variable? Please advice. Thank you very much for all yours sincere help.</p>