Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering

Browse Topics

- Getting started
- Data Types
- Modules
- Operators in VB6
- VB6 Variable
- VB6 Procedures
- VB6 Control Structures
- Loops in VB6
- VB6 Exit Do & With End With
- Arrays in VB6
- User-Defined Data Types
- VB6 Constants
-
VB6 Built-in Functions
- Date and Time in VB6
- VB6 Controls
- TextBox Control
- ComboBox & OptionButton
- Label & Frame
- PictureBox & ImageBox
- Timer Control
- ListBox & ComboBox
- VB6 ScrollBar
- Control Arrays in VB6
- Files controls in VB6
- VB6 CheckBox
- Forms in VB6
- Menus in VB6
- MDI Form in VB6
- InputBox
- MessageBox
- Mouse events
- Mouse Move
- Error Handling
-
Error Handling (2)
-
VB6 Database

You are here: Visual Basic > VB6 (Beginners Tutorial)

Tutorial Main Page | Previous Page | Contents | Next Page

Finding Specific Records

• In addition to using the data control to move through database records, we can write Visual Basic code to accomplish the same, and other, tasks. This is referred to as programmatic control. In fact, many times the data control Visible property is set to False and all data manipulations are performed in code. We can also use programmatic control to find certain records.

• There are four methods used for moving in a database. These methods replicate the capabilities of the four arrow buttons on the data control:

MoveFirst - Move to the first record in the table.
MoveLast - Move to the last record in the table.
MoveNext - Move to the next record (with respect to the current record) in the table.
MovePrevious - Move to the previous record (with respect to the current record) in the table.

• When moving about the database programmatically, we need to test the BOF (beginning of file) and EOF (end of file) properties. The BOF property is True when the current record is positioned before any data. The EOF property is True when the current record has been positioned past the end of the data. If either property is True, the current record is invalid. If both properties are True, then there is no data in the database table at all.

• These properties, and the programmatic control methods, operate on the Recordset property of the data control. Hence, to move to the first record in a table attached to a data control named dtaExample, the syntax is:

dtaExample.Recordset.MoveFirst

• There is a method used for searching a database:

Find - Find a record that meets the specified search criteria.

This method also operates on the Recordset property and has three arguments we will be concerned with. To use Find with a data control named dtaExample:

dtaExample.Recordset.Find Criteria,NumberSkipped,SearchDirection

• The search Criteria is a string expression like a WHERE clause in SQL. We won’t go into much detail on such criteria here. Simply put, the criteria describes what particular records it wants to look at. For example, using our book database, if we want to look at books with titles (the Title field) beginning with S, we would use:

Criteria = “Title >= ‘S’”

Note the use of single quotes around the search letter. Single quotes are used to enclose strings in Criteria statements. Three logical operators can be used: equals (=), greater than (>), and less than (<).

• The NumberSkipped argument tells how many records to skip before beginning the Find. This can be used to exclude the current record by setting NumberSkipped to 1.

• The SearchDirection argument has two possible values: adSearchForward or adSearchBackward. Note, in conjunction with the four Move methods, the SearchDirection argument can be used to provide a variety of search types (search from the top, search from the bottom, etc.)

• If a search fails to find a record that matches the criteria, the Recordset’s EOF or BOF property is set to True (depending on search direction). Another property used in searches is the Bookmark property. This allows you to save the current record pointer in case you want to return to that position later. The example illustrates its use.


  

Tutorial Main Page | Previous Page | Contents | Next Page

   

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved