title: VBA global variable value disappear in other sub
body: <p>I have a global variable called flag set up. I can access flag from every module in my code, but when I assign it the value 1 in Sub Command97_Click(), for some reason flag does not keep the value to Sub Form_BeforeUpdate(Cancel As Integer). When I print the flag in Sub Form_BeforeUpdate it is not equal to 1 anymore. I know that this is silly, but I am new to vba... </p>
  
  <p>Bear in mind my code does more than this, but I am only keeping the basic for my question.</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>Public flag As Integer
  
  Private Sub Command97_Click()
      flag = 1
  End Sub
  
  Private Sub Form_BeforeUpdate(Cancel As Integer)
      If flag = 1 Then
           DoCmd.RunCommand acCmdUndo
           MsgBox "Flag = " &amp; flag, vbInformation
           Exit Sub
      End If
  End Sub
  </code></pre>