不好意思,整段代码如下: 
Dim i, sql
 Dim rs As New ADODB.Recordset, cn As New ADODB.Connection
 
    Set cn = New ADODB.Connection
    Set rs = New ADODB.Recordset
 If  = "" Then
  MsgBox "只有输入了合同号,才能进行查询!", vbOKOnly, "提示"
 Exit Sub
 End If
 If rs.State = adStateOpen Then rs.Close
          sql = "SELECT A.hth, A.pf, B.ylpf, B.ylsh, B.cgfs, Sum(B.dh*A.sl) AS yyl FROM A INNER JOIN B ON (A.hth = B.hth) AND (A.pf = B.pf) GROUP BY A.hth, A.pf, B.ylpf, B.ylsh, B.cgfs where A.hth='" &  & "' ORDER BY A.pf ASC "
    cn.CursorLocation = adUseClient
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Jet OLEDB:Database Password=;Persist Security Info=False;"
        rs.Open sql, cn, 1, 1
        Set Me.DataGrid1.DataSource = Nothing
        Set Me.DataGrid1.DataSource = rs