INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Run-Time error 3021

Run-Time error 3021

(OP)
I am trying to get records from database according to a particular date: for instance 08/06/1996 (short date).

And here is my code

Private Sub cmdSearch_Click()
Dim cn As New ADODB.Connection
Dim sqlDOH As String
Dim DOH As String
Dim RS As New ADODB.Recordset
DOH = txtDateHire.Text
cn.Open "DSN=employee.mdb;UID=Admin;PWD="
cn.CursorLocation = adUseClient
'***********************************************
sqlDOH = "Select empid,empname,Date_Hire from Employee WHERE Date_Hire >=" & txtDateHire.Text & ""
Set RS = cn.Execute(sqlDOH)
If Not RS.BOF Then
        Do While Not RS.BOF
        txtEmpID.Text = RS!Empid
        txtEmpName.Text = RS!EmpName
        txtDateHire.Text = RS!Date_Hire
        RS.MoveNext
        Loop
End If
End Sub

When I run this script and type in the date 08/06/1996 in the text box, in stead of the right record, I get the last record with 07/20/2000 date and an error message "3021" with the following statement:

"Either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record."

I am not sure what I am doing wrong here.

Please help.

Thanks in advance

RE: Run-Time error 3021

(OP)
I am trying to get records from database according to a particular date: for instance 08/06/1996 (short date).


And here is my code. If I correct the code to:
If Not RS.BOF Then
Do While Not RS.EOF
      ;;;;
;;;;
rs.movenext
as below:  

Private Sub cmdSearch_Click()
Dim cn As New ADODB.Connection
Dim sqlDOH As String
Dim DOH As String
Dim RS As New ADODB.Recordset
DOH = txtDateHire.Text
cn.Open "DSN=employee.mdb;UID=Admin;PWD="
cn.CursorLocation = adUseClient
'***********************************************
sqlDOH = "Select empid,empname,Date_Hire from Employee WHERE Date_Hire >=" & txtDateHire.Text & ""
Set RS = cn.Execute(sqlDOH)
If Not RS.BOF Then
        Do While Not RS.EOF
        txtEmpID.Text = RS!Empid
        txtEmpName.Text = RS!EmpName
        txtDateHire.Text = RS!Date_Hire
        RS.MoveNext
        Loop
End If
End Sub

I stillget the last record with 07/20/2000 date only this time without any error message.

So what is the right way to pull a record out of a database based on one single date let's say "Employee hire date" for instance?

Please help.

Thanks in advance

RE: Run-Time error 3021

Seems like you are in the wrong forum.

if it is an Access dbms you are using


sqlDOH = "Select empid,empname,Date_Hire from Employee WHERE Date_Hire >=#" & txtDateHire.Text & "#"

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close