Library tutorials & articles

Data Control

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

Comments

  1. 28 Jun 2007 at 13:19

    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 Project. But whenever I run the Project it displays the following error message:

    Runtime Error # 3343

    Unrecognized Database Format

    Please tell me what to do now.

    Thanks & Best Regards

    From

    Bhasker Kumar

    Email :- bhaskerno123@yahoo.co.in

     

  2. 28 Jul 2005 at 08:27

    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.

  3. 28 Jul 2005 at 08:20

    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.

  4. 28 Jul 2005 at 07:50

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

  5. 28 Jul 2005 at 07:35

    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

  6. 04 Sep 2003 at 19:32

    The download link doesn't work...

  7. 28 Nov 2002 at 22:54

    I am currently having problems searching a dbase3 file using the data control.  Can anyone offer any suggestions as to searching?  I am using bound controls (testboxes) to display the data.  I can use the directional buttons to move forward and back but I cannot search for a specific value.


    Thanx in Advance

  8. 26 Jan 2002 at 13:34
    What is the table name?
    is it the recordsource or what?
  9. 07 Nov 2001 at 06:10

    it's good control

  10. 01 Jan 1999 at 00:00

    This thread is for discussions of Data Control.

Leave a comment

Sign in or Join us (it's free).

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

Want to stay in touch with what's going on? Follow us on twitter!