title: Display current logged in user from database in a text box in visual studio
body: <p>So I have an account settings portion of a program I am working on. I am wondering how to display the current logged in user in this window. I am using visual studio express and access 2007. I have learned that, UserNameTextBox.Text = Environment.UserName will display the username of the local machine you are logged into. I have a create new user feature where it will add a new user to the "users table" with username password email and admin. Under my account settings I want the form to display the users "username and email" to allow them to make changes. But i have no idea where to start. I do not want it to display the Windows login, just the username and email from the account logged in with inside the application. This is the LOGINSCREEN form. </p>
  
  <p>Public Class LOGINSCREEN</p>
  
  <pre><code>Dim loginerror As String
  Public Function login()
  
      Dim cnn As New ADODB.Connection 'creates database connection
      Dim User As New ADODB.Recordset
  
      Dim CHEMusers As String 'query
      Dim username As String 'look to db for username
      Dim userpassword As String 'look to db for password
      Dim userfound As Boolean ' condition do loop
  
  
      cnn.Open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" &amp; "chem.accdb;")
  
      User.Open("Users", cnn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
  
      userfound = False
      login = False
  
      CHEMusers = "Username ='" &amp; usernameTextBox.Text &amp; "'"
  
      Do
          User.Find(CHEMusers)
  
          If User.BOF = False And User.EOF = False Then
  
              username = User.Fields("Username").Value.ToString
  
              userpassword = User.Fields("UserPassword").Value.ToString
  
  
              If username &lt;&gt; usernameTextBox.Text Then
                  User.MoveNext()
              Else
                  userfound = True
                  If userpassword = PasswordTextBox.Text Then
                      User.Close()
                      cnn.Close()
                      Return True
  
                  Else
  
                      loginerror = "Password does not match."
                      User.Close()
                      cnn.Close()
                      Return False
                  End If
              End If
  
          Else
              loginerror = "Please enter a valid username."
              User.Close()
              cnn.Close()
              Return False
  
          End If
      Loop Until userfound = True
  
  
      User.Close()
      cnn.Close()
      Return False
  
  
  End Function
  
  Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
  
  
      If login() = True Then
  
          MessageBox.Show("You have logged in successfully!", "Login Message")
  
          Dim portal As New PORTAL
          portal.Show()
          Me.Hide()
  
      Else
          MessageBox.Show(loginerror, "Login Message")
      End If
  
  
  End Sub
  </code></pre>