title: Access VBA Passing a Variable between modules
body: <p>I have two modules. One runs a procedure (various queries, etc) and the other one is supposed to write to a table, such as the Username, changes made, etc. </p>
  
  <p>I've successfully written a script that writes to a table and one that reads from the table. However, I cannot pass that variable from one to the other. </p>
  
  <p>For example, here is the code that is trying to read a "User" value from the sub/function <code>ReadSystemTbl()</code></p>
  
  <pre><code>Sub Testing()
  
    Dim x As String
  
    x = ReadSystemTbl("User")
  
    MsgBox x
  
  End Sub
  </code></pre>
  
  <p>And here is the code that finds the value and returns it:</p>
  
  <pre><code>Public Function ReadSystemTbl(FindField As String)
  
  Dim db As Database
  Dim rs As Recordset
  Dim SystemField As Field, SystemValue As Field
  Dim results As String
  
  Set db = CurrentDb()
  Set rs = db.OpenRecordset("SystemTbl")
  Set SystemField = rs.Fields("SystemField")
  Set SystemValue = rs.Fields("SystemValue")
  
  Do Until rs.EOF
   If SystemField = FindField Then
      results = SystemValue
   End If
   rs.MoveNext
  Loop
  
  End Function
  </code></pre>