和书上打得一模一样,可是居然出现该对象不支持该操作的错误(书配盘的源码可通过)
和书上打得一模一样,可是居然出现该对象不支持该操作的错误(书配盘的源码可
通过)
Option Explicit
Private Const BIBLIO_PATH = "C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb"
Private Sub Form_Load()
Dim dbfBiblio As Database, recSelect As Recordset
Dim strSQL As String, strSubQuery As String
Dim intCount As Integer, intGridRow As Integer
'get the database name and open the database
Set dbfBiblio = DBEngine.Workspaces(0).OpenConnection(BIBLIO_PATH)
'build the subquery ,starting with its SELECT statement
strSubQuery = "SELECT City FROM Publishers as Tmp " & _
"GROUP BY City,State " & _
"HAVING COUNT(*)>1 AND State=Publishers.State"
'build the SQL statement
'start by designating the fields to be included in the recordset
'and the WHERE IN clause
strSQL = "SELECT City,State,[Company Name] FROM Publishers " & _
"WHERE City IN (" & strSubQuery & ") " & _
"ORDER BY State,City"
'run the query
Set recSelect = dbfBiblio.OpenRecordset(strSQL, dbOpenSnapshot)
'make sure the query returned at least one record
If recSelect.RecordCount > 0 Then
'get a count of records in the recordset and display it on the form
recSelect.MoveLast
intCount = recSelect.RecordCount
lblcount.Caption = intCount
'initialize the grid
With grdValues
.Rows = intCount + 1
.ColWidth(0) = 700: .ColWidth(1) = 2000: .ColWidth(2) = 4000
.Row = 0: .Col = 0: .Text = "State"
.Col = 1: .Text = "City"
.Col = 2: .Text = "Publisher"
End With
'populate the grid
recSelect.MoveFirst
For intGridRow = 1 To intCount
With grdValues
.Row = intGridRow
.Col = 0: .Text = recSelect![State]
.Col = 1: .Text = recSelect![City]
.Col = 2: .Text = recSelect![Company Name]
End With
recSelect.MoveNext
Next intGridRow
End If
End Sub