VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Form1 
   Caption         =   "VB6 例11-11 多表数据组合"
   ClientHeight    =   1710
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5205
   LinkTopic       =   "Form1"
   ScaleHeight     =   1710
   ScaleWidth      =   5205
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "删除"
      Height          =   315
      Left            =   3900
      TabIndex        =   1
      Top             =   1380
      Width           =   1155
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
      Bindings        =   "V6bj11-12d.frx":0000
      Height          =   1275
      Left            =   120
      TabIndex        =   0
      Top             =   60
      Width           =   4575
      _ExtentX        =   8070
      _ExtentY        =   2249
      _Version        =   393216
      FixedCols       =   0
   End
   Begin VB.Data Data1 
      Caption         =   "Data1"
      Connect         =   "Access"
      DatabaseName    =   ""
      DefaultCursorType=   0  '缺省游标
      DefaultType     =   2  '使用 ODBC
      Exclusive       =   0   'False
      Height          =   345
      Left            =   120
      Options         =   0
      ReadOnly        =   0   'False
      RecordsetType   =   1  'Dynaset
      RecordSource    =   ""
      Top             =   1320
      Width           =   2835
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
    Dim mpath As String

Private Sub Command1_Click()
    Dim db As Database
    Dim sql As String
    Set db = OpenDatabase(mpath + "Student.mdb")
    sql = "Delete * From temp Where 平均成绩<80"
    db.Execute sql
    Data1.Refresh
End Sub

Private Sub Form_Load()
    On Error Resume Next
    Dim db As Database, sql As String
    mpath = App.Path
    If Right(mpath, 1) <> "\" Then mpath = mpath + "\"
    Set db = OpenDatabase(mpath + "Student.mdb")
    sql = "Select 学号,Avg(成绩) As 平均成绩 Into temp "
    sql = sql & " From 学生成绩表 Group by 学号 Order By Avg(成绩) Desc"
    '删除已存在的表temp
    db.Execute "Drop Table temp;"
    db.Execute sql
    Data1.DatabaseName = mpath + "student.mdb"
    Data1.RecordSource = "Select 基本情况.学号, 基本情况.姓名, " _
    & " 基本情况.专业,基本情况.性别,temp.平均成绩" _
    & " From 基本情况,temp Where 基本情况.学号=temp.学号"
    Data1.Refresh
    db.Close
End Sub
