title: Run Code error in Access Macro
body: <p>I am trying to make a macro in Access that will run VBA code.  I trying am using the RunCode command to Run a function that will run a VBA function that I have already created but for some reason it says it can't find it and I am really confused why. I have posted a picture of the macro as well as the code below.  Any help would be greatly appreciated.</p>
  
  <p>Macro:</p>
  
  <p><a href="http://imgur.com/uankmL0" rel="nofollow">http://imgur.com/uankmL0</a></p>
  
  <p>Code:</p>
  
  <pre><code>Function Totals()
  
  Dim db As Database
  
  Set db = CurrentDb
  foldername = CurrentProject.Path &amp; "\GeneralTotals"
  deleteTotals = "DELETE * FROM Totals"
  
  totalVerified = "INSERT INTO Totals([TOTAL VERIFIED FORMULARIES], [TOTAL AVAILABLE FOR IMPORT], [TOTAL SHOULD BE IMPORTED], [TOTAL RECENTLY IMPORTED]) " &amp; _
  "SELECT A.cnt, B.cnt, C.cnt, D.cnt " &amp; _
  "FROM ( " &amp; _
      "SELECT COUNT([FORMULARY ID]) as cnt " &amp; _
      "FROM VerifiedFormularies " &amp; _
  ") AS A " &amp; _
  ", ( " &amp; _
      "SELECT COUNT([FORMULARY ID]) as cnt " &amp; _
      "FROM ImportMetricsIDs " &amp; _
  ") as B " &amp; _
  ", ( " &amp; _
      "SELECT COUNT([FORMULARY ID]) as cnt " &amp; _
      "FROM ShouldImportMetricsIDsTable " &amp; _
      "WHERE [IMPORTSTATUS]= 'Yes' " &amp; _
  ") AS C " &amp; _
  ", ( " &amp; _
      "SELECT COUNT([LATEST]) as cnt " &amp; _
      "FROM VerifiedFormularies " &amp; _
      "WHERE [LATEST]= 'Yes' " &amp; _
  ") AS D "
  
  
  db.Execute deleteTotals
  db.Execute totalVerified
  
  
  DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel5, "Totals", foldername
  
  MsgBox ("Totals have been exported to: " &amp; foldername)
  
  End Function
  </code></pre>