title: Login Form in Visual Basic 2010 and Access Database
body: <p>When trying to login on my system I get a "COMexception was unhandled" error on the line that contains:</p>
  
  <blockquote>
    <p>DBConn.Open("Provider = Microsoft.Jet.OLEDB.4.0;"</p>
  </blockquote>
  
  <p>This is the code for the function that searches the database:</p>
  
  <pre><code>Public Function Login()
      Dim DBConn As New ADODB.Connection
      Dim User As New ADODB.Recordset
      Dim Username As String
      Dim UserDB As String
      Dim PassDB As String
      Dim UserFound As Boolean
  
      DBConn.Open("Provider = Microsoft.Jet.OLEDB.4.0;" &amp; "DataSource = '" &amp; Application.StartupPath &amp; "\LoginDB.mdb'")
      User.Open("UserTable", DBConn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
  
      UserFound = False
      Login = False
      Username = "Username = '" &amp; txtboxUsername.Text &amp; "'"
  
      Do
          User.find(Username)
          If User.BOF = False And User.EOF = False Then
              UserDB = User.Fields("Username").Value.ToString
              PassDB = User.Fields("Password").Value.ToString
              If UserDB &lt;&gt; txtboxUsername.Text Then
                  User.movenext()
              Else
                  UserFound = True
                  If PassDB = txtboxPassword.Text Then
                      User.Close()
                      DBConn.Close()
                      Return True
                  Else
                      LoginError = "Invalid Password"
                      User.Close()
                      DBConn.Close()
                      Return False
  
                  End If
              End If
          Else
              LoginError = "Invalid Username"
              User.Close()
              DBConn.Close()
              Return False
          End If
      Loop Until UserFound = True
  
  End Function
  </code></pre>