我有一个表单,用于查询我想发送电子邮件的客户。
我正在尝试创建一种跟踪发送到客户端的电子邮件的方法。下面的代码只将第一条记录添加到我的表中。我一直试图找出循环无济于事。
Private Sub TrackEmails_Click()
Dim db As DAO.Recordset
Dim rstEmails As Recordset
Set db = Me.RecordsetClone
Set rstEmails = CurrentDb.OpenRecordset("EmailTracking", dbOpenDynaset)
rstEmails.AddNew
rstEmails!CustomerID = Me!ID
rstEmails!Email = Me!Email
rstEmails.Update
rstEmails.Close
End Sub
根据Jason的建议更新了代码。当我只是尝试在表中添加12条记录时,intI计数达到了32767。
Private Sub Command666_Click()
Dim db As DAO.Database
Dim rstEmails As DAO.Recordset
Dim intI As Integer
Set db = CurrentDb
Set rstEmails = db.OpenRecordset("EmailTracking", dbOpenDynaset)
With Me.Form.Recordset
If (.RecordCount) Then
.MoveFirst
intI = 1
With rstEmails
Do Until .EOF
rstEmails.AddNew
rstEmails!CustomerID = Me!ID
rstEmails!Email = Me!Email
rstEmails.Update
.MoveNext
intI = intI + 1
Loop
End With
rstEmails.Close
Set rstEmails = Nothing
结束如果
结束End Sub