error object required at "If ((rs.Fields(0) = username.Text)..."

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ranjana jadhav
    New Member
    • Jan 2013
    • 1

    error object required at "If ((rs.Fields(0) = username.Text)..."

    Code:
    Private Sub Command1_Click()
    
    Set conn = New ADODB.Connection
    conn.CursorLocation = adUseClient
    conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\VB98\professor_data.mdb;Persist Security Info=False;"
    conn.Open
    Set rs = New ADODB.Recordset
     With rs
         Set .ActiveConnection = conn
            .CursorType = adOpenDynamic
            .LockType = adLockOptimistic
            .Source = "select * from professor_data"
            .Open
    
    
            If rs.RecordCount <> 0 Then
                rs.MoveFirst
                While Not rs.EOF
                    If ((rs.Fields(0) = username.Text) And (rs.Fields(1) = password.Text)) Then
                        MsgBox "SUCCESFUL LOGIN "
                        Form1.Show
                        Else
                        MsgBox "INVALID USER"
                    End If
                    rs.MoveNext
                Wend
            End If
    
        End With
    
        rs.Close
        Set rs = Nothing
    End Sub
    Last edited by Meetee; Jan 1 '13, 08:09 AM. Reason: Use code tags <code/> around your code
  • Ramk
    New Member
    • Nov 2008
    • 61

    #2
    rs.Fields(0) returns the Object type. Cast it similar to rs.Fields(0).To String() before checking with username.Text etc. Also do check for NULL of the returned object such as
    Code:
    if (rs.Fields(0) != null)
    {
     //your code...
    }

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      ranjana jadhav

      Posted code without explanation or question is subject to deletion. Please read the FAQ and posting guidlines before posting your question.

      By, simply stating that your code "doesn't work," posting a generic/jargon filled error along with code that appears to have had very little if any troubleshooting performed, and expecting someone to help doesn't usually result in much of an answer and may result in your thread being deleted. Instead, please tell us what you were expecting to happen, what actually happened, for each error: the EXACT title, error number, and descriptions that occurred and at what line in your posted code the error occurred. These are the minimum requirements for posting a question of this nature.

      Comment

      Working...