Article ID: 195472
Article Last Modified on 8/3/2005
Option Explicit
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim i As Integer
Dim FindLastName As String
Private Sub Command1_Click()
' Remove previously saved bookmark from collection
If (DataGrid1.SelBookmarks.Count <> 0) Then
DataGrid1.SelBookmarks.Remove 0
End If
' Prompt user for desired author's last name
FindLastName = InputBox("Please enter the author's last name you
want to search for", "Find")
rs.Find "au_lname = '" & FindLastName & "'", , , 1
' Append your bookmark to the collection of selected rows
DataGrid1.SelBookmarks.Add rs.Bookmark
End Sub
Private Sub Form_Load()
' Open your ADO connection where "Pubs" is an ODBC DSN that
' points to pubs database in SQL Server
cn.Open "Pubs"
' Create your command to query for all records in Authors table
With cmd
.ActiveConnection = cn
.CommandText = "select * from authors"
End With
' Open your recordset
With rs
' Set rs properties
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
' Call open using active command
.Open cmd
End With
' Populate the DataGrid providing rs as the data source
Set DataGrid1.DataSource = rs
End SubKeywords: kbhowto kbsetup kbconfig kbctrl KB195472