title: Using NT login as part of SQL query run via VBA in Access 2007
body: <p>In Access 2007, I'm trying to use the NTlogin to retrieve a value from a table via a SQL query (see code below). WHen the form loads, I get an error message saying "Compile Error: Expected Function or Variable". Can someone tell me how to fix this error. </p>
  
  <pre><code>Private Sub Form_Load()
  
      Dim UserName As String
      Dim strSQL As String
      Dim strDept As String
  
      UserName = Environ("USERNAME")
  
      strSQL = "SELECT DEPT FROM IDs WHERE NTLOGIN =" &amp; UserName
  
      strDept = DoCmd.RunSQL(strSQL)
  
      cmdSave.Enabled = False
      cmdEdit.Enabled = True
      cmdPrevious.Enabled = True
      cmdNext.Enabled = True
  
  End Sub
  </code></pre>