如何将DAO记录集添加为数据表子表单中的行

时间:2016-09-02 16:46:36

标签: access-vba ms-access-2007

我有以下代码将产品信息从销售报价转移到租赁资格表。产品转到数据表视图中的子窗体,但是,记录集中的每一行只更新子窗体的第一行。

sql = "SELECT ProdID, ProdQty, ProdPrice FROM ProductsQuoted WHERE quoteID = " & quoteeID
  Set db = CurrentDb
  Set rs = CurrentDb.OpenRecordset(sql)

  If Not (rs.EOF And rs.BOF) Then
     rs.MoveFirst
     Do Until rs.EOF
        [Forms]![Qualification]![QualificationDetails]![Item] = rs.Fields("ProdID").Value
        [Forms]![Qualification]![QualificationDetails]![Qty] = rs.Fields("ProdQty").Value
        [Forms]![Qualification]![QualificationDetails]![Price] = rs.Fields("ProdPrice").Value
        rs.MoveNext
    Loop
  End If

如何让数据集中的每条记录更新子表单上的新行?

1 个答案:

答案 0 :(得分:1)

好的,我能够使用DoCmd.GoToRecord,acNewRec并满足我的需求。

sql = "SELECT ProdID, ProdQty, ProdPrice FROM ProductsQuoted WHERE quoteID = " & quoteeID
    Set db = CurrentDb
    Set rs = db.OpenRecordset(sql)

       If Not (rs.EOF And rs.BOF) Then
        rs.MoveFirst
        Do Until rs.EOF
            Debug.Print rs.Fields("ProdID") & ", " & rs.Fields("ProdQty") & ", " & rs.Fields("ProdPrice")
            QualificationDetails.SetFocus
            QualificationDetails!Item.SetFocus
            DoCmd.GoToRecord , , acNewRec
            [Forms]![Qualification]![QualificationDetails]![Item] = rs.Fields("ProdID").Value
            [Forms]![Qualification]![QualificationDetails]![Qty] = rs.Fields("ProdQty").Value
            [Forms]![Qualification]![QualificationDetails]![Price] = rs.Fields("ProdPrice").Value
            rs.MoveNext
        Loop
    End If