run-time error '3021'

Either BOF and EOF

Page 1 of 1

2 Replies - 12322 Views - Last Post: 19 October 2008 - 06:37 PM Rate Topic: -----

#1 pinayaaron   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-October 08

run-time error '3021'

Posted 19 October 2008 - 05:42 AM

[i]

please help me...
I'm doing an database in Visual Basic 6.0. I had problem doing in search button code. If I run the program and press the "search button" it is okey it can find a record if had a record. But the problem is if without a record it will appear "Run-Time error '3021': Either BOF and EOF is True, or the current record has been deleted. Requested Operation requires a current record."

this is the code:


Dim Rec_Find As String
Rec_Find = InputBox("Enter Student ID Number", "Find Record")
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
If Rec_Find = Text3.Text Then
	Exit Sub
Else
10 'Seck
	Adodc1.Recordset.MoveNext
	On erro GoTo 20
	If Rec_Find = Text3.Text Then
		Exit Sub
	Else
		GoTo 10
	End If
End If
	
20 'Sent Erro report
	MsgBox "No record Found", , "DBase Report"
	
End Sub


please help me.

Mod edit - Please :code:
~BetaWar

Is This A Good Question/Topic? 0
  • +

Replies To: run-time error '3021'

#2 thava   User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,607
  • Joined: 17-April 07

Re: run-time error '3021'

Posted 19 October 2008 - 05:42 PM

try this code
Dim Rec_Find As String
Rec_Find = InputBox("Enter Student ID Number", "Find Record")
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
If Rec_Find = Text3.Text Then
    Exit Sub
Else
10 'Seck
'/***************new code**********/
    if   Adodc1.Recordset.Eof then
         Exit sub
    End if
'/***************new code**********/
    Adodc1.Recordset.MoveNext
    On erro GoTo 20
    If Rec_Find = Text3.Text Then
        Exit Sub
    Else
        GoTo 10
    End If
End If
    
20 'Sent Erro report
    MsgBox "No record Found", , "DBase Report"
    
End Sub



or try this code if you want to handle the Error

Dim Rec_Find As String
''/***************place your code on the top**********/
On erro GoTo 20
''/***************place your code on the top**********/
Rec_Find = InputBox("Enter Student ID Number", "Find Record")
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
If Rec_Find = Text3.Text Then
    Exit Sub
Else
10 'Seck
    Adodc1.Recordset.MoveNext
''/***************comment your code**********/
    'On erro GoTo 20
'/***************comment your code**********/
    If Rec_Find = Text3.Text Then
        Exit Sub
    Else
        GoTo 10
    End If
End If
    
20 'Sent Erro report
    MsgBox "No record Found", , "DBase Report"
    
End Sub


for me this both ways are wrong

why dont you try this one
Dim criteria As String
criteria = "field_name =" & Value
Adodc1.Recordset.Find  criteria, , , 1
' the 1 specifies the first record when the search start every time
If Adodc1.Recordset.EOF Then
MsgBox "Record not found"
End If


This post has been edited by thava: 19 October 2008 - 05:43 PM

Was This Post Helpful? 0
  • +
  • -

#3 pinayaaron   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-October 08

Re: run-time error '3021'

Posted 19 October 2008 - 06:37 PM

thava!

thank you so much it is ok right now!

thank you, thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1