我有一个MS Access报告,可以从查询中获取数据。
数据集的结构如下:
[field 1] [field 2] ... [email]
该报告在标题中有一个“发送邀请”按钮,它接受[email]
字段中的所有值,构建一串以分号分隔的地址,并打开Outlook邀请。
我试图使用RecordsetClone
来循环它,但我发现这种方法在报告中不可用。
还有另一种方法来完成工作吗?
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset(Me.RecordSource)
看起来我有一个长期但效率低下的解决方案:
' Get the recordset by performing a new query Dim rs As DAO.Recordset: Dim MailArray As Variant qry = "SELECT EmployeeID FROM Registry WHERE SessionID = " & CStr(TempVars("SID").Value) Set rs = CurrentDb.OpenRecordset(qry) ' Move the recordset in an array with an esoteric formula found in StackOverflow With rs .MoveLast .MoveFirst MailArray = .GetRows(.RecordCount) End With ' Loop through the array and build the string with the email addresses separated by a semicolon Dim i As Integer: Dim strList As String If (UBound(MailArray, 2)) > 0 Then For i = 0 To UBound(MailArray, 2) strList = strList + DLookup("MailAddress", "Employee", "ID=" & (MailArray(0, i))) & ";" Next i Else MsgBox "No people enrolled in this session.", vbOKOnly, "Attenzione!" End If Erase MailArray ' Feed the string to Outlook 8< -------------------------------------
但它确实有效。
PS:谢谢骚扰爸爸的支持。