如何在MS ACCESS中插入像Excel函数一样的新行

我需要find一种方法来使MS Access中的网格,并通过代码VBA插入新的行,只是如何Excel的行为。

你看过连续的表格和数据表吗?

在数据库中复制电子表格行为是一个好主意

代码插入行:在行之间插入行

首先创build一个临时表然后像这个主表一样处理这个表

代码是和我一起工作,这里的代码:

Sub InsertRows() On Error GoTo ErrorNu Dim SQLP As String Dim Con As New ADODB.Connection Dim Conx As New ADODB.Connection Dim Rst As New ADODB.Recordset Dim Rs As New ADODB.Recordset Dim Rsx As New ADODB.Recordset Dim Rn As New ADODB.Recordset Dim Rd As New ADODB.Recordset Dim Num As Long Dim intRows Dim arrEmployees As Variant Dim x As Integer, Y As Integer Set Con = CurrentProject.Connection Con.BeginTrans sqlo = " select max(AutoRec)as maxa from Note_Custom " Set Rn = Con.Execute(sqlo) SQLP = " SELECT AutoRec, TextCOspoId, OuerM,Note" SQLP = SQLP & " , TextBillId,NuCOspoId,dateTybe FROM Note_Custom ORDER BY AutoRec" Rs.Open SQLP, Con, adUseClient, adOpenStatic, adCmdText sqlo = " UPDATE Note_Custom SET TextBillId = ''" sqlo = sqlo & " WHERE AutoRec > " & 0 Con.Execute (sqlo) intRows = Val(Rn!maxa) Num = 1 arrEmployees = Rs.GetRows(intRows) Y = 0 For x = 0 To intRows - 1 If x = Val(SelTop - 1) Then Y = 1 Rs.AddNew Rs![AutoRec] = arrEmployees(0, x) Rs![TextBillId] = 1 Rs.Update End If Rs.AddNew Rs![AutoRec] = arrEmployees(0, x) + Y Rs![TextCOspoId] = arrEmployees(1, x) Rs![OuerM] = arrEmployees(2, x) Rs![Note] = arrEmployees(3, x) Rs![NuCOspoId] = arrEmployees(5, x) Rs![dateTybe] = arrEmployees(6, x) Rs![TextBillId] = 1 Rs.Update Next x sqlo = "DELETE * FROM Note_Custom where TextBillId = """"" Con.Execute (sqlo) Con.CommitTrans SelFiled = Me.SelTop Me.Requery sqlo = "SELECT Last(AutoRec) AS LastAuto,First(AutoRec) AS FirstAuto,Count(AutoRec) AS CountAuto FROM Note_Custom" Set Rd = Con.Execute(sqlo) If Me.SelTop <> AutoRec Or Rd!LastAuto <> Rd!CountAuto Then Refix End If DoCmd.GoToRecord , , acGoTo, SelFiled 'Me.SelTop = SelFiled If RecType = False Then Forms![Ncustom]!Edite.Enabled = True Forms![Ncustom]!Viewer1.Enabled = False Forms![Ncustom]!DELETE.Enabled = False End If arrEmployees = Empty Rs.Close Con.Close Set Rs = Nothing Set Con = Nothing Exit Sub ErrorNu: SelFiled = Me.SelTop Me.Requery Me.SelTop = SelFiled End Sub