Private Sub cmdok_Click()
'将列表框中的选中的名字批量写入表marktemp
Dim frm As Form, ctl As Control
Dim varItm As Variant
Set frm = Forms!mark
Set ctl = frm!List2
For Each varItm In ctl.ItemsSelected
Set rst = CurrentDb.OpenRecordset("marktemp", dbOpenDynaset)
For i = 0 To Me.List2.ListCount - 1
If Me.List2.Selected(i) = True Then
rst.AddNew
rst.Fields("name").Value = Me.List2.Column(0, i)
rst.Fields("m1").Value = Me.List2.Column(1, i)
rst.Fields("m2").Value = Me.List2.Column(2, i)
rst.Update
End If
Next i
rst.Close
Me.marktemp_child.Requery
cmdsave.Enabled = True
DoCmd.SetWarnings True
复制代码
[attach]45373[/attach]
我一般习惯于用ADO……不过,DAO用起来也差不多。
作者: kangking 时间: 2011-4-18 14:29
Private Sub cmdok_Click()
'将列表框中的选中的名字批量写入表marktemp
Dim i As Integer
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("marktemp", dbOpenDynaset)
With rst
For i = 0 To Me.List2.ListCount - 1
If Me.List2.Selected(i) Then
myname = List2.Column(0, i)
mydm = List2.Column(1, i)
rst.AddNew
rst("name") = myname
rst("m1") = mydm
rst.Update
End If
Next
End With
rst.Close
Set rst = Nothing
Me.marktemp_child.Requery
cmdsave.Enabled = True
DoCmd.SetWarnings True
End Sub 作者: wktt6833 时间: 2011-4-18 15:02
感谢各位的帮助,昨于在网上找了大半天,没找到 相同的事例,现在问题解决了.作者: huangdexun 时间: 2012-12-4 00:23
各有千秋,很好的实例。