Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 61,208 times

Contents

Related Categories

Data Control - Finding Records

Finding Records

When using a Database, a crucial function is to be able to find specific records. You can do this using the Find and Seek functions of the Data control.

Data1.Recordset.FindFirst criteria
Data1.Recordset.FindLast criteria
Data1.Recordset.FindNext criteria
Data1.Recordset.FindPrevious criteria
Data1.Recordset.Seek comparison, key1, key2...key13

Find method

Begins searching at Search direction

FindFirst 

Beginning of recordset End of recordset 

FindLast 

End of recordset Beginning of recordset 

FindNext 

Current record End of recordset 

FindPrevious 

Current record Beginning of recordset 

The criteria property of the Find methods is quite simple, and takes the following format:

FieldName = Value

If FieldName contains a space, it must be contained by ":

Data1.Recordset.FindFirst "ISBN = '0-0131985-2-1'"

To see if either of these method has found an item check the NoMatch property:

If Data1.Recordset.NoMatch = True Then
    Msgbox "No match found"
End If

As the FindFirst method will move you to the beginning of the recordset if there is no match, you should bookmark the position, and return to it if no match is found.

Dim varBookmark As Variant
varBookmark = datTitles.Recordset.Bookmark
datTitles.Recordset.FindFirst "ISBN = '0-0131985-2-12'"
If datTitles.Recordset.NoMatch = True Then
    datTitles.Recordset.Bookmark = varBookmark
    MsgBox "No match found"
End If

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [71] Data Control

    Posted by Bhaskerit on 28 Jun 2007

    Hi ! All,


    I'm new in VB Programming and trying with all your given examples. I'm trying to create a database project. I've created a table in Access 2000 and wants to attatch it with my VB ...

  • hi

    Posted by Regie on 28 Jul 2005

    im a newbie in vb, im working now with the examples above, my objective is to save,add, delete files to the database i can't do it. there is a propmted error invalid or unqualified references.

  • hi there

    Posted by Regie on 28 Jul 2005

    i am a newbie in vb,and now im currently working with the tutorials that are post above, my objective is that i want to save, add or delete a file to my stand-alone database. thanks for fast replies.

  • Posted by chandrababu on 28 Jul 2005

    At least give some explanation about the environment or
    what is you objective.

  • Error

    Posted by Regie on 28 Jul 2005

    hi there, why is that i can't add or save new file? the error propmt is
    "invalid or unqualified reference." plz send me an answer or email it to me plz..hoping to hear from you. ASAP..thanks