Article ID: 148361
Article Last Modified on 10/11/2006
' This code assumes you have Microsoft Access 7.0 installed and have
' the Northwind.mdb sample database installed in the default
' location.
Sub CreateRecordSet()
Dim oldDbName As String
Dim wspDefault As Workspace
Dim dbsNorthwind As Database
Dim strSQL As String
Dim rstFromQuery As Recordset
'Set the path to the database
oldDbName = "C:\Msoffice\access\samples\Northwind.mdb"
'Create a default workspace Object
Set wspDefault = DBEngine.Workspaces(0)
'Create a Database object
Set dbsNorthwind = wspDefault.OpenDatabase(oldDbName)
'The SQL statement
strSQL = "SELECT Employees.LastName, Employees.FirstName, " & _
"Employees.Country FROM Employees Employees " & _
"WHERE (Employees.Country='USA')"
'Create a Snapshot Type Recordset from the SQL query
Set _
rstFromQuery = dbsNorthwind.OpenRecordset(strSQL,dbOpenSnapshot)
'Show the number of fields returned
MsgBox "there are " & rstFromQuery.Fields.Count & _
" fields that were returned"
'Move to the last record in the recordset
rstFromQuery.MoveLast
'Show the number of records returned
MsgBox "there are " & rstFromQuery.RecordCount & _
" records that were returned"
End Sub
176476 OFF: Office Assistant Not Answering Visual Basic Questions
OpenRecordset Method
Additional query words: 8.00 97 xl97 DAO Database RecordSet visualbasic editor XL
Keywords: kbdtacode kbhowto kbprogramming KB148361