title: Automating MS Access VBA procedure - assign string variable to InputBox
body: <p>I am trying to automate at first glance a very simple task via C# - to pass a string value to an inputBox called through VBA function.</p>
  <p>In order to do that I have used Visual C# .NET Automation Client to create an instance of MS Access and open the required database:</p>
  <pre><code>using System.Management.Automation;
  using Access = Microsoft.Office.Interop.Access;
  
  Access.Application oAccess = new Access.Application();
          oAccess.Visible = true;
          oAccess.OpenCurrentDatabase(&quot;D:\\path\\to\\database&quot;, false, &quot;&quot;);
        
  </code></pre>
  <p>In the mentioned database we have a Macro that calls a VBA function via the &quot;<code>RunCode</code>&quot; action. This <code>public Function</code> then calls another <code>private Sub</code>:</p>
  <pre><code>Public Function ImportMappingDatabases()
    ImportMappings InputBox(&quot;Specify Path&quot;, &quot;Path&quot;, mstrcDefaultPath), _
      InputBox(&quot;Choose Package&quot;, &quot;Package&quot;, &quot;&quot;)
  End Function
  
  Private Sub ImportMappings(Optional Path As String = mstrcDefaultPath, Optional Package As String = &quot;&quot;)
  </code></pre>
  <p>Here is where I got stuck. The input box with the title &quot;<code>Path</code>&quot; wants the user to input a certain path that the later code uses for reasons that do not need to be explained. The same is valid for the input box with the title &quot;<code>Package</code>&quot;. I assume there is a way to &quot;pass&quot; a string value from the C# code to the input box entry field, but I do not know how to refer to the input box and set the value. After that is done the user is required to click on the &quot;OK&quot; button or the &quot;Cancel&quot;, the same question applies, I will try to synthesize it in 1 sentence:</p>
  <p>How to get a reference of that input box, set the input value, and &quot;click&quot; one of the buttons?</p>
  <p><strong>More information:</strong></p>
  <p>I am calling the public function via: <code>oAccess.Run(&quot;ImportMappingDatabases&quot;);</code></p>
  <p>I can <strong>not</strong> modify the VBA functions/subs.</p>
  <p><strong>Update 1:</strong></p>
  <p>Check my answer below.</p>