你可以在这样做:
设一个自变量,i=1;  
do while not M_rs.eof
      将i赋给报表字段
      i=i+1
loop
   

解决方案 »

  1.   

    此例中使用msflexgrid。Dim rst As Recordset
    Dim strSQL As StringPrivate Sub cmdAddNew_Click()    With MSFlexGrid1
            .AddItem ""
            .Col = 0
            .Row = .Rows - 1
            .RowHeight(.Row) = 300
            .Text = Str(.Row)
            '如果记录数大于9,则上卷至最后一行
            If .Rows > 9 Then
                .TopRow = .Rows - 9
            End If
            .Col = 1
            .SetFocus
            Call MSFlexGrid1_DblClick
        End WithEnd SubPrivate Sub Form_Load()
        
        If strSkin <> "" Then
            Skin1.LoadSkin strSkin
            Skin1.ApplySkin hWnd
        End If
        
        Dim i As Integer
        
        strSQL = "select EID,EName from Employee order by EID"
        Set rst = gdb.OpenRecordset(strSQL)    Label1.Caption = "如果您发现有的记录始终不能保存,请检查编号是否有重复!" + vbCr + _
            vbCr + "您更新的数据将会在窗口退出时自动保存。" + vbCr + vbCr + "当前已保存的员工数 "    With MSFlexGrid1
            .Cols = 3
            If rst.RecordCount = 0 Then
    '            MsgBox "目前尚无记录!", vbCritical, "提示"
                .Rows = 1
                .RowHeight(0) = 300
                .Row = 0
                '设置第0列为序号
                .ColWidth(0) = 500
                .ColAlignment(0) = flexAlignLeftCenter
                .Text = "序号"
                .Col = 1
                .ColAlignment(1) = flexAlignCenterCenter
                .Text = "姓名"
                .Col = 2
                .ColAlignment(2) = flexAlignCenterCenter
                .Text = "编号"
                Label1.Caption = Label1.Caption + "0"
            Else
                rst.MoveLast
                rst.MoveFirst
                Label1.Caption = Label1.Caption + Str(rst.RecordCount)
                '设置第0列为序号
                .Col = 0
                .ColWidth(0) = 500
                .ColAlignment(0) = flexAlignCenterCenter
                .Rows = rst.RecordCount + 1
                For i = 0 To rst.RecordCount
                    .RowHeight(i) = 300
                    .Row = i
                    .Text = Str(i)  '设置行号
                Next i
                .Row = 0
                .Text = "序号"  '消除首行行号
                '设置第1列为姓名,第2列为编号
                .Col = 1
                .ColAlignment(1) = flexAlignCenterCenter
                .Row = 0
                .Text = "姓名"
                rst.MoveFirst
                Do While Not rst.EOF
                    .Row = rst.AbsolutePosition + 1
                    .Text = rst("EName")
                    rst.MoveNext
                Loop
                .Col = 2
                .ColAlignment(2) = flexAlignCenterCenter
                .Row = 0
                .Text = "编号"
                rst.MoveFirst
                Do While Not rst.EOF
                    .Row = rst.AbsolutePosition + 1
                    .Text = rst("EID")
                    rst.MoveNext
                Loop
            End If
            '设置焦点
            .Col = 0
            .Row = 0
            .Width = .ColWidth(0) + .ColWidth(1) + .ColWidth(2) + 200
            Frame1.Width = .Width + (.Left - Frame1.Left) * 2
        End WithEnd Sub
    Private Sub cmdDel_Click()    With MSFlexGrid1
            Dim c As Integer, r As Integer
            c = .Col: r = .Row
            If r = 0 Then
                MsgBox "请选择您要删除的列!", vbCritical, "提示"
                Exit Sub
            End If
            .Col = 0
            If MsgBox("您真的要删除 " + .Text + " 号人员的档案吗?", vbQuestion + vbYesNo, "确认") = vbNo Then
                .Col = c
                Exit Sub
            Else
                If .Rows <= 2 Then
                    .Rows = 1
                    Exit Sub
                End If
                .RemoveItem r
                '调整序号
                Dim i As Integer
                For i = r To .Rows - 1
                    .Row = i
                    .Text = Str(i)
                Next i
                .Refresh
                .Col = c
            End If
        End With