访问VBA 2016从一种形式插入多条记录

时间:2018-12-28 18:44:25

标签: access-vba ms-access-2010

在这个问题上,我疯了,我有一个表格,其中填充了可变数量的数据行,每行的末尾都有一个复选框。然后,用户在要继续记录剪切卡的每一行旁边的窗体上放置复选标记,然后单击命令按钮。我只需要插入一行,并在如何获取空白上插入所有选中的行。这是我的代码:

Public Sub bttnCutCard_Click()
    Dim sqlTmp As String
    Dim tmpReq As Variant
    Dim tmpHnb As Variant
    Dim tmpLt As Variant
    Dim tmpSA As Variant
    Dim tmpCou As Variant
    Dim tmpcc As Variant
    Dim rs As DAO.Recordset
    Dim SQLCut As String
    Dim tmprq As Variant
    Dim tmplot As Variant

    tmpcc = Me.Cutcard
    tmpReq = Me.ServiceReq
    tmpHnb = Me.HouseNumber
    tmpLt = Me.LotNumb
    tmpSA = Me.StreetName
    tmpCou = Me.County


        If tmpcc = -1 Then
        sqlTmp = "Insert into tmpdevcc (Requestnbr, HouseNmb, LTNBR, ServiceAddress, County) Values ( " & tmpReq & " ,'" & tmpHnb & "', '" & tmpLt & "', '" & tmpSA & "', '" & tmpCou & "')"
        DoCmd.RunCommand acCmdSaveRecord
        DoCmd.RunSQL sqlTmp
    Set rs = DBEngine(0)(0).OpenRecordset("tmpdevcc")
    Do While Not rs.EOF
    rs.MoveFirst
        SQLCut = "INSERT INTO tblCCnew ([Requestnbr], HouseNmb, LTNBR, ServiceAddress, County) Values('" & tmpReq & "', '" & tmpHnb & "', '" & tmpLt & "', '" & tmpSA & "', '" & tmpCou & "')"
        DoCmd.RunSQL SQLCut

        tmprq = DLookup("[Requestnbr]", "tmpdevcc", tmpcc = -1)
        tmpLt = DLookup("LTNBR", "tmpdevcc", tmpcc = -1)
        DoCmd.OpenForm "Cutcardenter", , , "[tblCCnew].[RequestNbr] =" & tmprq & " And [tblCCnew].[LTNBR] =" & tmpLt
    rs.MoveNext
    Loop
    rs.Close

    Exit Sub

    Else
    MsgBox "No Cut cards check off"
    End If

Exit Sub

任何人都可以帮助我或就如何更有效地做到这一点提出建议,这将是很棒的。

0 个答案:

没有答案