title: Passing a variable from one form to another
body: <p>I created a login screen for my DB which works.</p>
  <p>I would like to pass a variable to a text box that will be on the 'Main Menu' form once you're validated.</p>
  <p>Here's my code when you click 'Login'.</p>
  <pre class="lang-vb prettyprint-override"><code>'Login button submit, validate, welcome message &amp; main menu navigation
  Private Sub cmd_login___Click()
  
      Dim db As DAO.Database
      Dim rst As DAO.Recordset
      Dim strSQL As String
   
      'query to check if login details are correct
      strSQL = &quot;SELECT Name FROM LoginQuery WHERE Username = &quot;&quot;&quot; &amp; Me.txt_username.Value &amp; &quot;&quot;&quot; AND Password = &quot;&quot;&quot; &amp; Me.txt_password.Value &amp; &quot;&quot;&quot;&quot;
    
      Set db = CurrentDb
      Set rst = db.OpenRecordset(strSQL)
      If rst.EOF Then
          MsgBox prompt:=&quot;Incorrect username/password. Try again.&quot;, buttons:=vbCritical, title:=&quot;Login Error&quot;
          Me.txt_username.SetFocus
      Else
          MsgBox prompt:=&quot;Hello, &quot; &amp; rst.Fields(0).Value &amp; &quot;.&quot;, buttons:=vbOKOnly, title:=&quot;Login Successful&quot;
          DoCmd.Close acForm, &quot;frm_login&quot;, acSaveYes
          DoCmd.Close
          DoCmd.OpenForm &quot;MainMenu&quot;
      End If
   
      Set db = Nothing
      Set rst = Nothing
  </code></pre>
  <p>This line displays a prompt on screen saying Login successful with the &quot;rst.Fields(0).Value&quot; variable which is the users full name, but I'd prefer less windows and buttons to press and instead, pass this variable to a new blank form with a textbox on it.</p>
  <pre class="lang-vb prettyprint-override"><code>MsgBox prompt:=&quot;Hello, &quot; &amp; rst.Fields(0).Value &amp; &quot;.&quot;, buttons:=vbOKOnly, title:=&quot;Login Successful&quot;
  </code></pre>
  <p>I named the textbox on the <em>MainMenu</em> form, <em>txt_welcome</em>.</p>
  <p>I tried appending the below in the IF statement:</p>
  <pre class="lang-vb prettyprint-override"><code>Dim name As String
  name = &quot;SELECT Name FROM LoginQuery WHERE Username = &quot;&quot;&quot; &amp; Me.txt_username.Value &amp; &quot;&quot;&quot; AND Password = &quot;&quot;&quot; &amp; Me.txt_password.Value &amp; &quot;&quot;&quot;&quot;
  [MainMenu]![txt_welcome].Value = name
  </code></pre>
  <hr />
  <pre class="lang-vb prettyprint-override"><code>[MainMenu]![txt_welcome].Value = &quot;dsfadsf&quot;
  </code></pre>
  <hr />
  <pre class="lang-vb prettyprint-override"><code>MainMenu!txt_welcome.value = &quot;justdisplaysomethingplz&quot;
  </code></pre>