Ms access 如何在MS ACCESS中插入类似Excel的新行函数

Ms access 如何在MS ACCESS中插入类似Excel的新行函数,ms-access,excel,vba,Ms Access,Excel,Vba,我需要找到一种方法,在MS Access中创建网格,仅通过代码VBA插入新行 excel的具体表现。您看过连续表单和数据表吗 在数据库中复制电子表格行为很少是个好主意代码InsertRows:在两行之间插入行 首先创建一个临时表,然后像处理主表一样处理该表 代码是和我一起工作的 下面是代码: Sub InsertRows() On Error GoTo ErrorNu Dim SQLP As String Dim Con As New ADODB.Connection

我需要找到一种方法,在MS Access中创建网格,仅通过代码VBA插入新行
excel的具体表现。

您看过连续表单和数据表吗


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

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

首先创建一个临时表,然后像处理主表一样处理该表

代码是和我一起工作的 下面是代码:

 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
子插入行()
关于错误转到错误菜单
将SQLP设置为字符串
Dim Con作为新的ADODB连接
Dim Conx作为新的ADODB连接
将Rst设置为新ADODB.Recordset
将Rs设置为新ADODB.Recordset
将Rsx设置为新的ADODB.Recordset
将Rn设置为新ADODB.Recordset
将Rd设置为新ADODB.Recordset
Dim Num尽可能长
朦胧的内向
作为变体的员工
将x作为整数,Y作为整数
Set Con=CurrentProject.Connection
贝金特斯监狱
sqlo=“从注释\自定义中选择最大值(自动恢复)作为最大值”
Set Rn=Con.Execute(sqlo)
SQLP=“选择自动复制、TextCOspoId、OuerM、Note”
SQLP=SQLP&“、TextBillId、NuCOspoId、dateTybe来自注释\u AutoRec定制订单”
Rs.打开SQLP、Con、adUseClient、adOpenStatic、adCmdText
sqlo=“更新注释\u自定义设置TextBillId=”“
sqlo=sqlo&“WHERE AutoRec>”&0
Con.Execute(sqlo)
intRows=Val(Rn!maxa)
Num=1
arEmployees=Rs.GetRows(intRows)
Y=0
对于x=0到ws-1
如果x=Val(SelTop-1),则
Y=1
艾德纽卢比
Rs![AutoRec]=拖欠员工(0,x)
Rs![TextBillId]=1
Rs.更新
如果结束
艾德纽卢比
Rs![AutoRec]=拖欠员工(0,x)+Y
Rs![TextCOspoId]=拖欠员工(1,x)
Rs![OuerM]=拖欠员工(2,x)
Rs![注]=拖欠员工(3,x)
Rs![NuCOspoId]=拖欠员工(5,x)
Rs![dateTybe]=拖欠员工(6,x)
Rs![TextBillId]=1
Rs.更新
下一个x
sqlo=“从注释中删除*\u自定义,其中TextBillId=“””
Con.Execute(sqlo)
Con.CommitTrans
SelFiled=Me.SelTop
我,再询问
sqlo=“从注释中选择Last(AutoRec)作为LastAuto,选择First(AutoRec)作为FirstAuto,选择CountAuto(AutoRec)作为CountAuto\u Custom”
Set Rd=Con.Execute(sqlo)
如果我是SelTop AutoRec或Rd!拉斯特路!倒计时
Refix
如果结束
DoCmd.GoToRecord,acGoTo,自编
'Me.SelTop=SelFiled
如果RecType=False,则
形式![Ncustom]!Edite.Enabled=True
形式![Ncustom]!Viewer1.Enabled=False
形式![Ncustom]!DELETE.Enabled=False
如果结束
欠薪员工=空
Rs.Close
结案
设置Rs=无
设置Con=Nothing
出口接头
ErrorNu:
SelFiled=Me.SelTop
我,再询问
Me.SelTop=SelFiled
端接头

如果你把这些句子都作为单独的答案贴出来,我会把它们都投赞成票!