title: Public variables are not REALLY public in VBA in Forms
body: <p>Below is a question that I will answer myself, however it caused a GREAT deal of frustration for me and I had a lot of trouble searching for it on the web, so I am posting here in hopes of saving some time &amp; effort for others, and maybe for myself if I forget this in the future:
  <br><br>
  For VBA (in my case, MS Excel), the <strong><code>Public</code> declaration is supposed to make the variable (or function) globally accessible by other functions or subroutines in that module, as well as in any other module.
  <br><br>
  Turns out this is not true, in the case of <code>Forms</code></strong>, and I suspect also in <code>Sheets</code>, but I haven't verified the latter.
  <br><br>
  In short, the <strong>following will NOT create a public, accessible variable</strong> when created in a <code>Form</code>, and will therefore crash, saying that the bYesNo and dRate variables are undefined in mModule1:
  <br></p>
  
  <pre><code>(inside fMyForm)
  Public bYesNo As Boolean`
  Public dRate As Double
  
  Private Sub SetVals()
      bYesNo = Me.cbShouldIHaveADrink.value
      dRate = CDec(Me.tbHowManyPerHour.value)
  End Sub
  (Presume the textbox &amp; checkbox are defined in the form)
  
  (inside mModule1)
  Private Sub PrintVals()
      Debug.Print CStr(bYesNo)
      Debug.Print CStr(dRate)
  End Sub
  </code></pre>
  
  <p><br>
  However, if you make the slight alteration below, it all will work fine:
  <br></p>
  
  <pre><code>(inside fMyForm)
  
  Private Sub SetVals()
      bYesNo = Me.cbShouldIHaveADrink.value
      dRate = CDec(Me.tbHowManyPerHour.value)
  End Sub
  (Presume the textbox &amp; checkbox are defined in the form)
  
  (inside mModule1)
  Public bYesNo As Boolean`
  Public dRate As Double
  Private Sub PrintVals()
      Debug.Print CStr(bYesNo)
      Debug.Print CStr(dRate)
  End Sub
  </code></pre>
  
  <p><br></p>
  
  <p><code>mModule1</code> will work perfectly fine and, assuming that the fMyForm is always called first, then by the time the <code>PrintVals</code> routine is run, the values from the textbox and checkbox in the form will properly be captured.
  <br><br>
  I honestly cannot possibly fathom what MS was thinking with this change, but the lack of consistency is a huge suck on efficiency, learning idiosyncracies like these, which are so poorly documented that a Google search in 2013 for something that has likely been around for a decade or more is so challenging to search.</p>