学员问题描述:
把“TMP_样品库”追加到“TMP_样品检测明细”,“TMP_样品检测明细”参数编号用“TMP_样品库”里的检测参数按;分割分别追加,检测数量固定1次。
实现功能的代码如下:
Private Sub Command0_Click()
On Error Resume Next
Dim A() As String
Dim i As Integer
Dim rst As ADODB.Recordset
Dim rstTmp As ADODB.Recordset
Set rst = New ADODB.Recordset
Set rstTmp = New ADODB.Recordset
rst.Open "TMP_样品库", CurrentProject.Connection, 2, 3
rstTmp.Open "TMP_样品检测明细", CurrentProject.Connection, 2, 3
Do Until rst.EOF
A = Split(rst![检测参数], ";")
For i = LBound(A) To UBound(A) - 1
rstTmp.AddNew
rstTmp![样品编号] = rst![样品编号]
rstTmp![参数编号] = A(i)
rstTmp![检测数量] = 1
Next i
rst.MoveNext
Loop
rstTmp.Update
rst.Close
rstTmp.Close
Set rst = Nothing
Set rstTmp = Nothing
MsgBox "数据追加成功!"
DoCmd.OpenTable "TMP_样品检测明细"
End Sub
点击下载示例:
点击下载此附件