title: When does MS-Access Report VBA Code run
body: <p>I have been searching for a few days for a simple answer to this question:</p>
  
  <p>Does the VBA code behind/in a report run when the report is open in Preview mode AND hidden?</p>
  
  <p>I have inherited a P-O-S (Not Point-Of-Sale) Access 2003 database (Written mostly in German) that has a report with a very long and complicated VBA module attached to it. I need the code to execute when the report is run in Preview mode but it does not.</p>
  
  <p>The report is called from a form with the following line:</p>
  
  <pre><code>DoCmd.OpenReport "Fertigungszettel",acPreview, , , acHidden
  </code></pre>
  
  <p>I then close the form with the following line</p>
  
  <pre><code>DoCmd.Close acReport, "Fertigungszettel", acSaveNo
  </code></pre>
  
  <p>The problem is that the code in/behind/attached to the report does not seem to run. I thought maybe I needed to delay the closing so that Access had time to run code so I added the following to the report vba</p>
  
  <pre><code>Private Declare Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long)
  
  Public SleepPls(ByVal ISecs As Long)
    Sleep(ISecs * 1000)
  End Sub
  </code></pre>
  
  <p>And I added the line to call it like this:</p>
  
  <pre><code>SleepPls(10)
  </code></pre>
  
  <p>But it made no difference.</p>
  
  <p>Can anyone either explain this to me or point me somewhere that will explain this in a simple way. I ask for a simple way because I will have to explain this to upper management who are not Dev's. (Not even close).</p>
  
  <p>Thanks in advance.</p>