我在做报表输出时(用的是VB自带的设计器),为什么在输出时的记录与我选择条件后的记录不一致,但后台库中表的记录却是我想得到的。代码如下:Private Sub cmdOk_Click()
    strwhere = ""
    Set rs = New ADODB.Recordset
    Set cm = New ADODB.Command
    cm.ActiveConnection = DEfirst.Confirst
    rs.CursorType = adOpenStatic
    rs.CursorLocation = adUseClient
    rs.LockType = adLockPessimistic
    strsql = "delete * from temp_sql"
    cm.CommandType = adCmdText
    cm.CommandText = strsql
    cm.Execute
    strsql = "insert into temp_sql select curdate ,depart_name ," & _
             "file_name,paper_type,paper_num,people,kind from total where "
    If optRept.Item(0).Value = True Then
        If chkType.Item(0).Value = 1 Then
            strwhere = "kind='" & chkType.Item(0).Caption & "'"
        End If
        If chkType.Item(1).Value = 1 Then
            If strwhere = "" Then
                strwhere = "kind='" & chkType.Item(1).Caption & "'"
            Else
                strwhere = strwhere & " or kind='" & chkType.Item(1).Caption & "'"
            End If
        End If
        strsql = strsql & strwhere
        cm.CommandType = adCmdText
        cm.CommandText = strsql
        cm.Execute
        datrep.Show
        'Debug.Print chkType.Item(0).Value
   End If
End Sub

解决方案 »

  1.   

    把在加个dim m_rs as new adodb.recorderset
          set m_rs=cm.execute
          set datrep.datasource=m_rs
          用这个方法试一试
      

  2.   

    不行啊。报表的数据源是不是不能为Recordset类型呢?如果这样,报表中的数据只能与后台的表联系,要是这样报表数据如何根据条件动态显示呢??
    请知道的朋友告诉我,谢谢!!!!