title: How to get instance of actual form from MS Access in a Module (VBA)
body: <p>I have a bunch of forms in MS Access 2010. All of them are bound forms but I tricked them to only save once I click <code>btnSave</code>.</p>
  
  <p>The main problem is that I have quite a lot of code that is the same for every form in some events such as <code>form_beforeUpdate()</code> or <code>form_afterUpdate()</code> or <code>form_Load()</code>. An example:</p>
  
  <pre><code>Private Sub btnSave_Click()
   'Check first that all fields have been filled
   If CheckAllFields = True Then
       Exit Sub
   End If
   TempSaveRecord = True
   Me.Dirty = False 'this will make an attempt of form_Update()
   Form_Load 'After Saving we restart the data
  End Sub
  
  Private Sub Form_BeforeUpdate(Cancel As Integer)
   If TempSaveRecord = False Then
     Me.Undo
     Exit Sub
   End If
  End Sub
  </code></pre>
  
  <p><code>CheckAllFields</code> is just a routine that checks whether all the required fields are not <code>null</code>:</p>
  
  <pre><code>Private Function CheckAllFields() As Boolean
    Dim Ctrl As Control
    CheckAllFields = False
  
    'Check for unfilled fields
    For Each Ctrl In Me.Controls
       If Ctrl.Tag = "required" And IsNull(Ctrl) Then
                  MsgBox "The field " &amp; Ctrl.Name &amp; " has not been filled."
          CheckAllFields = True
          Exit For
       End If
    Next Ctrl
  End Function
  </code></pre>
  
  <p>I would like to do all of this in just one Module, but I can't find a way to get the actual instance of the form in that moment. Any help would be greatly appreciate it.</p>
  
  <p>Thanks</p>