Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


RDO: Moving To The First Record In A Result Set

To move to the first record in an RDO result set, you can use the rdoResultset method MoveFirst. Let’s see an example. In this case, we’ll move to the first record in the result set named resultset that we’ve opened in our RDO code example, the rdocode project (see “A Full-Scale RDO Example” earlier in this chapter), when the user clicks the appropriate button:

Private Sub cmdFirst_Click()
    On Error GoTo ErrLabel
    resultset.MoveFirst
...
    Exit Sub

ErrLabel:
   MsgBox Err.Description
End Sub

After moving to the new record, we display the data in that record’s fields in the program’s text boxes, Text1 and Text2:

Private Sub cmdFirst_Click()
    On Error GoTo ErrLabel

    resultset.MoveFirst
    Text1.Text = resultset("Name")
    Text2.Text = resultset("Grade")

    Exit Sub

ErrLabel:
    MsgBox Err.Description
End Sub

RDO: Moving To The Last Record In A Result Set

To move to the last record in an RDO result set, you can use the rdoResultset method MoveLast. Let’s see an example. In this case, we’ll move to the last record in the result set named resultset that we’ve opened in our RDO code example, the rdocode project (see “A Full-Scale RDO Example” earlier in this chapter), when the user clicks the appropriate button:

Private Sub cmdLast_Click()
    On Error GoTo ErrLabel

    resultset.MoveLast
...
    Exit Sub

ErrLabel:
    MsgBox Err.Description
End Sub

After moving to the new record, we display the data in that record’s fields in the program’s text boxes, Text1 and Text2:

Private Sub cmdLast_Click()
    On Error GoTo ErrLabel

    resultset.MoveLast

    Text1.Text = resultset("Name")
    Text2.Text = resultset("Grade")

    Exit Sub

ErrLabel:
    MsgBox Err.Description
End Sub

RDO: Moving To The Next Record In A Result Set

To move to the next record in an RDO result set, you can use the rdoResultset method MoveNext. Let’s see an example. In this case, we’ll move to the next record in the result set named resultset that we’ve opened in our RDO code example, the rdocode project (see “A Full-Scale RDO Example” earlier in this chapter), when the user clicks the appropriate button. We check to make sure we’re not trying to move past the end of the record set with the EOF property, and if so, we make sure to move to the last record instead:

Private Sub cmdNext_Click()
    On Error GoTo ErrLabel

    If Not resultset.EOF Then resultset.MoveNext
    If resultset.EOF And resultset.RowCount > 0 Then
        resultset.MoveLast
    End If
...
    Exit Sub

ErrLabel:
    MsgBox Err.Description
End Sub

After moving to the new record, we display the data in that record’s fields in the program’s text boxes, Text1 and Text2:

Private Sub cmdNext_Click()
    On Error GoTo ErrLabel

    If Not resultset.EOF Then resultset.MoveNext
    If resultset.EOF And resultset.RowCount > 0 Then
        resultset.MoveLast
    End If

    Text1.Text = resultset("Name")
    Text2.Text = resultset("Grade")

    Exit Sub

ErrLabel:
    MsgBox Err.Description
End Sub

RDO: Moving To The Previous Record In A Result Set

To move to the previous record in an RDO result set, you can use the rdoResultset method MovePrevious. Let’s see an example. In this case, we’ll move to the previous record in the result set named resultset that we’ve opened in our RDO code example, the rdocode project (see “A Full-Scale RDO Example” earlier in this chapter), when the user clicks the appropriate button. We check to make sure we’re not trying to move past the beginning of the record set with the BOF property, and if so, we make sure to move to the first record instead:

Private Sub cmdPrevious_Click()
    On Error GoTo ErrLabel

    If Not resultset.BOF Then resultset.MovePrevious
    If resultset.BOF And resultset.RowCount > 0 Then
        resultset.MoveFirst
    End If

    Text1.Text = resultset("Name")
    Text2.Text = resultset("Grade")

    Exit Sub

ErrLabel:
    MsgBox Err.Description
End Sub

After moving to the new record, we display the data in that record’s fields in the program’s text boxes, Text1 and Text2:

Private Sub cmdPrevious_Click()
    On Error GoTo ErrLabel

    If Not resultset.BOF Then resultset.MovePrevious
    If resultset.BOF And resultset.RowCount > 0 Then
        resultset.MoveFirst
    End If

    Text1.Text = resultset("Name")
    Text2.Text = resultset("Grade")

    Exit Sub

ErrLabel:
    MsgBox Err.Description
End Sub

RDO: Executing SQL

You can execute SQL statements with RDO objects when you open a result set, as we saw in “RDO: Creating A Result Set” in this chapter. You can also execute an SQL statement with the rdoConnection object’s Execute statements like this:

SQLSel = "Select * from students"
rdoConnection.Execute SQLSel

A Full-Scale ADO Example

To illustrate ADO data handling in code, we’ll build an ADO project—the adocode project. This application lets you open the db.mdb file we built in the previous chapter using ADO objects to edit records, add records, and even delete records. You can also move through the database using the arrow buttons you see in Figure 25.5.


Figure 25.5  The adocode project at work.

To edit a record, just type the new value(s) into the text box(es) and click the Update button. To add a record, use the Add button, type the new value(s) into the text box(es), and click the Update button. That’s all there is to it—your changes will be reflected in the original database. For reference, the code for this example is located in the adocode folder on this book’s accompanying CD-ROM.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.