Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error code 3021 When no records Found..

Status
Not open for further replies.

BatGrrrL

Programmer
Jan 21, 2003
12
AU
Hi Guys,

Have been handed a working project and have very little understanding of how it works (Im an asp web person)

Can someone please help me with the following.

When a user searches for a Surname in this program, if the Surname is not found it returns an error of:

"Run-time error '3021'
Method 'Value' of object 'Field' Failed"

I understand this is because the program still thinks it is returning results, but there is none to return.

The code is:

Private Sub cmdFind_Click()
' Remove previously saved bookmark from collection
If (DataGrid1.SelBookmarks.Count <> 0) Then
DataGrid1.SelBookmarks.Remove 0
End If

' Prompt user for last name
FindLastName = InputBox(&quot;Please enter the students's surname you want to search for&quot;, &quot;Find&quot;)

If StrPtr(FindLastName) = 0 Then
' If clicked cancel, then exit
Else

If Len(FindLastName) = 0 Then
' If nothing entered, then exit

Else

DataEnvironment1.rsDataTable.Find &quot;surname = '&quot; & FindLastName & &quot;'&quot;, , , 1
' Append your bookmark to the collection of selected rows
DataGrid1.SelBookmarks.Add DataEnvironment1.rsDataTable.Bookmark

End If 'Len(FindLastName)

End If 'StrPtr

End Sub

I don't know where to add the .. If BOF AND EOF stuff to display &quot;No records&quot;.. Can someone help me?

Is their more code I should paste? (And generally where would i find it?)

Also, my second question is, the program stops when it finds a match. How can I enable a message that allows the user to &quot;Find Next Match&quot;?

Thanks in advance!

BatGrrrL :)
Sorry for being so vague, today is my first day with VB.
 
You could put in some error handling to trap the error and then you could place whatever message you want. Check out FAQ222-1694 for explanations and examples on error handling.

Also, since you are just starting out in VB I would recommend that you look into using ADO for your database connection. It will give you far fewer headaches than the data environment, more programmers use it so there is more help available and it can be used with almost any database so there is less learning in the long run.

If you are interested there is a free ADO tutorial at and plenty of information in the VB help files and on msdn. Thanks and Good Luck!

zemp
 
Thanks Zemp,

I know alot about ADO in ASP so that would be a good start!

Thanks for the tips :)

BatGrrrL :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top