R
Rain
I am fairly new at VBA for Access. I have created codes to send emails. One
code picks a specific person to send an email to - I am getting a runtime
error that says "There must be at least one name or distribution list in the
To, Cc, or Bcc Box." Here is the code that looks for the email address:
Private Function HRRecip() As String
'Variable to define the recordset.
Dim myRS As DAO.Recordset
'Fill recordset with data from SQL.
Set myRS = CurrentDb.OpenRecordset(strSQLResult)
'Test if the recordset contains records.
If myRS.EOF And myRS.BOF Then
'No records found.
MsgBox "Your selection gave no rows, please try again."
GoTo exit_btnEmail_Click
End If
myRS.MoveFirst
'Loop through all records til end of file.
Do While Not myRS.EOF
If (myRS!Title) = "Admin Assistant" And (myRS!DateTerminated) =
"12/31/9999" Then
HRRecip = (" & myRS!Email & ")
End If
myRS.MoveNext
Loop
exit_btnEmail_Click:
'Close and clean up object variables, then done.
myRS.Close
Set myRS = Nothing
End Function
This is where I am having the problem:
With OlkHRMsg
'Make the "To" address of message.
Dim OlkHRRecip As Outlook.Recipient
Set OlkHRRecip = .Recipients.Add(HRRecip) <<<<<This line here says
"nothing"
OlkHRRecip.Type = olTo
.Subject = "Attendance Report"
'Need to specify HTML for body format.
.BodyFormat = olFormatHTML
'Must have Microsoft HTML Object Library checked in Tools/References.
.HTMLBody = strBodyHR
.send
End With
Please tell me what I am doing wrong. Thanks
code picks a specific person to send an email to - I am getting a runtime
error that says "There must be at least one name or distribution list in the
To, Cc, or Bcc Box." Here is the code that looks for the email address:
Private Function HRRecip() As String
'Variable to define the recordset.
Dim myRS As DAO.Recordset
'Fill recordset with data from SQL.
Set myRS = CurrentDb.OpenRecordset(strSQLResult)
'Test if the recordset contains records.
If myRS.EOF And myRS.BOF Then
'No records found.
MsgBox "Your selection gave no rows, please try again."
GoTo exit_btnEmail_Click
End If
myRS.MoveFirst
'Loop through all records til end of file.
Do While Not myRS.EOF
If (myRS!Title) = "Admin Assistant" And (myRS!DateTerminated) =
"12/31/9999" Then
HRRecip = (" & myRS!Email & ")
End If
myRS.MoveNext
Loop
exit_btnEmail_Click:
'Close and clean up object variables, then done.
myRS.Close
Set myRS = Nothing
End Function
This is where I am having the problem:
With OlkHRMsg
'Make the "To" address of message.
Dim OlkHRRecip As Outlook.Recipient
Set OlkHRRecip = .Recipients.Add(HRRecip) <<<<<This line here says
"nothing"
OlkHRRecip.Type = olTo
.Subject = "Attendance Report"
'Need to specify HTML for body format.
.BodyFormat = olFormatHTML
'Must have Microsoft HTML Object Library checked in Tools/References.
.HTMLBody = strBodyHR
.send
End With
Please tell me what I am doing wrong. Thanks