【发布时间】:2016-03-23 21:06:17
【问题描述】:
Dim strCell As String
Dim strProv As String
Dim strTextEmail As String
Dim oApp As Outlook.Application
Dim oMail As MailItem
Set oApp = CreateObject("Outlook.application")
Dim StrBCC As String
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim db As DAO.Database
Set db = CurrentDb
Set qdf = db.QueryDefs("Staff Query")
Set rst = qdf.OpenRecordset()
With rst
Do Until .EOF
strCell = Nz([CellPhone], "0")
strProv = Nz([CellProvider], "0")
MsgBox [CellPhone]
MsgBox [CellProvider]
If strCell = "0" Or strProv = "0" Then
MsgBox "MISSING DATA: Please double check the agent name, cell phone number and provider are entered in the staff table."
Else
Dim Clean As String
Dim Pos, A_Char
Pos = 1
For Pos = 1 To Len(strCell)
A_Char = Mid(strCell, Pos, 1)
If A_Char >= "0" And A_Char <= "9" Then
Clean = Clean + A_Char
End If
Next Pos
strCell = Clean
strProv = DLookup("[EmailExt]", "CellProviders", "[CellProvider]='" & strProv & "'")
strTextEmail = strCell & strProv
End If
StrBCC = StrBCC & strTextEmail & ";"
rst.MoveNext
Loop
End With
StrBCC = Left(StrBCC, Len(StrBCC) - 1)
Set oMail = oApp.CreateItem(olMailItem)
oMail.BCC = StrBCC
oMail.Display
Set oMail = Nothing
Set oApp = Nothing
Set rst = Nothing
我正在尝试遍历查询“员工查询”以向其中的每个人发送文本。除了它不会循环通过查询,它会循环通过我打开它的表单上的第一条记录并且它不会移动之外,我一切正常。 有人对此有什么建议吗? 先感谢您。
【问题讨论】:
-
在开始循环之前尝试 rst.MoveFirst
-
以及
MoveFirst先检查是否有记录-If Not .BOF AND Not .EOF THEN: DO UNTIL .EOF.....