869 873




Visual Basic 6 Black Book:Working With Database Objects In Code
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive 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 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




DAO: Moving To The First Record In A Record Set
To make the first record in a record set the current record, you use the MoveFirst method. For example, here’s how we move to the first record when the user clicks the appropriate button in our DAO code example, the daocode project (see the first topic in this chapter):


Private Sub Command4_Click()
dbrecordset.MoveFirst
...
End Sub


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


Private Sub Command4_Click()
dbrecordset.MoveFirst
Text1.Text = dbrecordset.fields(0)
Text2.Text = dbrecordset.fields(1)
End Sub


DAO: Moving To The Last Record In A Record Set
To make the last record in a record set the current record, you use the MoveLast method. For example, here’s how we move to the last record when the user clicks the appropriate button in our DAO code example, the daocode project (see the first topic in this chapter):


Private Sub Command7_Click()
dbrecordset.MoveLast
...
End Sub


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


Private Sub Command7_Click()
dbrecordset.MoveLast
Text1.Text = dbrecordset.fields(0)
Text2.Text = dbrecordset.fields(1)
End Sub


DAO: Moving To The Next Record In A Record Set
To move to the next record in a record set, making that record the current record, you use the MoveNext method. For example, in our DAO code example, the daocode project (see the first topic in this chapter), we move to the next record when the user clicks the appropriate button:


Private Sub Command6_Click()
dbrecordset.MoveNext
...


We can check if we’ve gone past the end of the record set with the EOF property; if this property is True, we should move back one record:


Private Sub Command6_Click()
dbrecordset.MoveNext
If dbrecordset.EOF Then
dbrecordset.MovePrevious
...


On the other hand, if the record we’ve moved to is a valid record, we display its fields in the program’s two text boxes, Text1 and Text2:


Private Sub Command6_Click()
dbrecordset.MoveNext
If dbrecordset.EOF Then
dbrecordset.MovePrevious
Else
Text1.Text = dbrecordset.fields(0)
Text2.Text = dbrecordset.fields(1)
End If
End Sub


DAO: Moving To The Previous Record In A Record Set
To move to the previous record in a record set, making that record the current record, you use the MovePrevious method. For example, in our DAO code example, the daocode project (see the first topic in this chapter), we move to the previous record when the user clicks the appropriate button:


Private Sub Command5_Click()
dbrecordset.MovePrevious
...


We can check if we’ve gone past the beginning of the record set with the BOF property; if this property is True, we should move forward one record:


Private Sub Command5_Click()
dbrecordset.MovePrevious
If dbrecordset.BOF Then
dbrecordset.MoveNext
...


On the other hand, if the record we’ve moved to is a valid record, we display its fields in the program’s two text boxes, Text1 and Text2:


Private Sub Command5_Click()
dbrecordset.MovePrevious
If dbrecordset.BOF Then
dbrecordset.MoveNext
Else
Text1.Text = dbrecordset.fields(0)
Text2.Text = dbrecordset.fields(1)
End If
End Sub


DAO: Deleting A Record In A Record Set
To delete a record in a DAO record set, you use the Delete method, and then you update the record set. For example, when the user clicks the Delete button in our DAO code example, the daocode project (see the first topic in this chapter), we clear the two text boxes, Text1 and Text2, that display the data for the current record and delete that record:


Private Sub Command8_Click()
Text1.Text = ""
Text2.Text = ""
dbrecordset.Delete
End Sub


DAO: Sorting A Record Set
To sort a record set, you can install the index you want to sort with in the record set’s Index property. For example, we can sort the record set in our DAO code example, the daocode project, with the index we’ve created this way:


Sub Sort_Click()
Set dbindex = td.Indexes(0)
dbrecordset.Index = dbindex.Name
...


After the record set is sorted, we display the first record in the two main text boxes, Text1 and Text2:


Sub Sort_Click()
Set dbindex = td.Indexes(0)
dbrecordset.Index = dbindex.Name
Text1.Text = dbrecordset.fields(0)
Text2.Text = dbrecordset.fields(1)
End Sub


DAO: Searching A Record Set
You can search a record set with an index; we just set its Index property to the index we want to search and then set its Seek property to the string we want to search for. Let’s see an example. When the user selects the Search menu item in our DAO code example, the daocode project (see the first topic in this chapter), we install the index based on the first field in the record set and show the dialog box named Search…, which appears in Figure 25.3:


Private Sub Search_Click()
Set dbindex = td.Indexes(0)
dbrecordset.Index = dbindex.Name
SearchForm.Show
End Sub



Figure 25.3  The DAO code example’s Search… dialog box.
After the user dismisses the Search… dialog box, we retrieve the text to search for from that dialog box’s text box and place that text in the record set’s Seek property, along with the command “=”, which indicates we want to find exact matches to the search text:


Sub SearchTable()
dbrecordset.Seek "=", SearchForm.Text1.Text
...


Besides =, you can also search using <, <=, >=, and >. When the search is complete, we display the found record in the daocode project’s main text boxes, Text1 and Text2:


Sub SearchTable()
dbrecordset.Seek "=", SearchForm.Text1.Text
Text1.Text = dbrecordset.fields(0)
Text2.Text = dbrecordset.fields(1)
End Sub






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.



Wyszukiwarka

Podobne podstrony:
870 873
873 (2)
873 923
demo cgi 873
865 869
NKS 869 g 4° Saxo, Gesta Danorum, Angersfragmentet

więcej podobnych podstron