dcsimg
Results 1 to 5 of 5

Thread: [SOLVED]Runtime Error 3021. EOF BOF... Creating customer msg to stop error 3021

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    112

    [SOLVED]Runtime Error 3021. EOF BOF... Creating customer msg to stop error 3021

    Hey guys im currently getting this error message.

    Run-time error '3021':
    Either BOF or EOF is True, or the current record has been deleted.
    Requested operation requires a current record.

    I understand that it means that I'm trying to find a record that is not there, how ever that is exactly the problem.

    What I mean is this... I'm designing a program for a login system, when a user tries to login, he will type his ID number, this ID number will obviously be checked on the database, but what if a invalid ID number is entered, an ID number that is not currently on the database?

    What I want to do is create a custom error message saying that the specified user ID or password is incorrect. How would I do this?

    ALSO...

    I'm using ADO, MySQL and VB6
    Last edited by Turkoloco; Aug 12th, 2009 at 10:23 AM. Reason: SOLVED

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,350

    Re: Runtime Error 3021. EOF BOF... Creating customer msg to stop error 3021

    Welcome to VBForums

    Thread moved to 'Database Development' forum (the 'VB6' forum is only meant for questions which don't fit in more specific forums).

    Assuming you are using recordset.Open ... (or Set recordset = conn.Execute ... ) , simply check for .EOF immediately after, eg:
    Code:
    rs.Open ....
    If rs.EOF Then
      Msgbox "No matching data"
    Else
      Msgbox "There is a match"
    End if
    (if you want to do the same check away from the .Open, you should use If (r.BOF And rs.EOF) Then )

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    112

    Re: Runtime Error 3021. EOF BOF... Creating customer msg to stop error 3021

    Hey si_the_geek, thanks for your help, i realised something, your code helped me for the first part of my program, it stopped the error occuring on the first part, of the program, but re appeared on the second part.

    I'll explain what I mean. Below is the part that worked

    (BTW, here is just a key so you know what means what just incase u get confused...

    txtUsername.text is where the username will be entered.
    txtPassword.text is where the password will be entered.
    testtext.text is where i will be checking if the password retrieved and the password typed matches.)

    Code:
    'Connect to MySQL DB and retrieve the password for the UserID entered
    Set rs = conn.Execute("SELECT EmployeePassword FROM tblemployeelogin WHERE EmployeeID =" & " " & txtUsername.Text)
    If rs.EOF Then
      MsgBox "No matching data"
    Else
      MsgBox "There is a match"
    End If
    Then the problem which occurs immediatly afterwards

    Code:
    'If the password entered matches the recordsheet, then display the message Success onto the testing box, if not, display fail
    If txtPassword.Text = rs("EmployeePassword") Then
    testtext.Text = "Success"
    Else
    testtext.Text = "fail"
    End If
     
    'Close the rs connection.
    rs.Close
    So what I thought I would do is, is this... I tried to use your suggestion of...

    Code:
    If rs.EOF Then
      MsgBox "No matching data"
    Else
      MsgBox "There is a match"
    End If
    but changed it to this...


    Code:
    If rs.EOF Then
      MsgBox "No matching data"
    If txtPassword.Text = rs("EmployeePassword") Then
    testtext.Text = "Success"
    Else
    testtext.Text = "fail"
    
    End If
    End If
    Result? Dead end , I know its possible and there is proberbly a minor mistake here somwhere, but i dont see what it is...

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    112

    Re: Runtime Error 3021. EOF BOF... Creating customer msg to stop error 3021

    No worries, found the mistake, Thanks a lot for your help i really appreciate it.

    it should of been like this,

    Code:
    Set rs = conn.Execute("SELECT EmployeePassword FROM tblemployeelogin WHERE EmployeeID =" & " " & txtUsername.Text)
    If rs.EOF Then
      MsgBox "No matching data"
    ElseIf txtPassword.Text = rs("EmployeePassword") Then
    testtext.Text = "Success"
    Else
    testtext.Text = "fail"
    End If
    Yeah, i know, that makes me look like a complete amateur, its just been such a long time since ive last made any decent VB programs.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,350

    Re: [SOLVED]Runtime Error 3021. EOF BOF... Creating customer msg to stop error 3021

    We all have moments like that - the important thing is that you worked it out in the end.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width