Dim lSum As Double
With Adodc1
If .Recordset.RecordCount > 0 Then
.Recordset.MoveFirst
Do While Not .Recordset.EOF()
lSum = lSum + Val(Adodc1.Recordset("考核").Value)
'这里还可指定其它字段统计
If Not .Recordset.EOF() Then .Recordset.MoveNext
Loop
End If
Frame3.Caption = "当前自定义查询结果:  考核合计数:" & lSum
End With
DataGrid1.Items[rs.RecordCount + 2].Cells[基层].Texttop = "找到" & rs.RecordCount & "条记录。"此条代码出错,不知道错在哪里?
请求高手帮助!

解决方案 »

  1.   

    datagrid绑定了记录集,它的行数是固定的.你为什么不在下面加一个Label显示呢.
      

  2.   

    我的行数是动态选择的,记录是根据条件选择不断变化的,所以我要在datagrid中所有记录后面一行输出“找到?条记录”
      

  3.   

    加一个Label控件,位置你随意。把
    DataGrid1.Items[rs.RecordCount + 2].Cells[基层].Texttop = "找到" & rs.RecordCount & "条记录。"
    这一句改成
    Me.Label1.Caption="找到" & rs.RecordCount & "条记录。"
      

  4.   


    你的这种需求,换 MSHFlexGrid 可能更灵活。
      

  5.   

    我是用ADODC连接ACCESS2002数据库在datagrid上显示出来,所以想输出到EXECL上
      

  6.   


    很不幸,只能告诉你,DataGrid 不是为这种用法设计的。
      

  7.   

    datagrid上的内容能输出execl上吗?
      

  8.   

    DataGrid控件绑定的数据集当然能写到EXCEL上.
      

  9.   

    Private Sub Command3_Click()
    On Error GoTo errExcel
     Dim i As Integer, j As Integer
        Dim xlApp As Excel.Application
        Dim xlBook As Excel.Workbook
        Dim xlSheet As Excel.Worksheet
        Dim File1, File2 As String
        
        File1 = App.Path & "\报表\!模板报表\!道路交通违法情况表.xls"
        File2 = App.Path & "\报表\道路交通违法情况表.xls"
        FileCopy File1, File2
        
        Set xlApp = CreateObject("Excel.Application")
        Set xlBook = xlApp.Workbooks.Open(File2)
        Set xlSheet = xlBook.Worksheets(1)
       xlSheet.Cells(4, 1) = "编制单位:" & "*********交通有限公司"
           
       ProgressBar1.Min = 0
       ProgressBar1.Max = 22 * 2
       ProgressBar1.Visible = True
        
        For i = 1 To DataGrid1.Row - 1
            DataGrid1.Row = i
            For j = 1 To 22
                DataGrid1.Col = j
                If IsNull(DataGrid1.Text) = False Then
                    xlSheet.Cells(i + 5, j) = DataGrid1.Text
                      End If
            Next
        Next
        
        xlSheet.Cells(i + 5, 2) = "制单:" & "*****"
        xlSheet.Cells(i + 5, 9) = "打印日期:"
        xlSheet.Cells(i + 5, 11) = Format(Date, "yyyy-mm-dd")
        
        For i = 2 To DataGrid1.Col - 2
            ProgressBar1.Value = ProgressBar1.Value + 1
            For j = 1 To 24
                xlSheet.Cells(i + 4, j).Select
                xlSheet.Cells(i + 4, j).Borders(xlDiagonalDown).LineStyle = xlNone
                xlSheet.Cells(i + 4, j).Borders(xlDiagonalUp).LineStyle = xlNone
                With xlSheet.Cells(i + 4, j).Borders(xlEdgeLeft)
                  .LineStyle = xlContinuous
                  .Weight = xlThin
                  .ColorIndex = xlAutomatic
                End With
                With xlSheet.Cells(i + 4, j).Borders(xlEdgeTop)
                  .LineStyle = xlContinuous
                  .Weight = xlThin
                  .ColorIndex = xlAutomatic
                End With
                With xlSheet.Cells(i + 4, j).Borders(xlEdgeBottom)
                  .LineStyle = xlContinuous
                  .Weight = xlThin
                  .ColorIndex = xlAutomatic
                End With
                With xlSheet.Cells(i + 4, j).Borders(xlEdgeRight)
                  .LineStyle = xlContinuous
                  .Weight = xlThin
                  .ColorIndex = xlAutomatic
                End With
            Next
        Next
        
        ProgressBar1.Visible = False
        xlApp.Visible = True
        
        xlBook.Save
        Exit Sub
    errExcel:
        If Err.Number = 70 Then
         MsgBox "请关闭Excel报表文件,再生成!", vbInformation, "系统提示"
      Else
           MsgBox Err.Description, vbInformation, "系统出错"
        End IfEnd Sub
    为什么文件不能拷贝!内容不能输出到execl上