Paul Ager
03-08-2011, 03:03 AM
Hi,
I am trying to add an attachment to an email from email addresses that are generated from a query in Access. I've tried to amalgamate to pieces of code to form one but I am getting the Complie Error: 'End If without block If' message. I'd really appreciate it if someone could cast their expert eye over the code below and see if they can find a solution.
Private Sub email_exp1_Click()
On Error GoTo Err_email_exp1_Click
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim strEmail As String
Dim strMsg As String
Dim oLook As Object
Dim oMail As Object
Set MyDb = CurrentDb
Set qdf = MyDb.QueryDefs("qryexp_may11")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next
Set rsEmail = qdf.OpenRecordset()
Set oLook = CreateObject("Outlook.Application")
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(0)) = False Then
Set oMail = oLook.createitem(0)
With oMail
.to = .Fields(0)
.body = "See attached"
.Subject = "Is the file attached"
.Attachments.Add("\\mynetwork\mynetworkfolder\example.doc")
.Send
End If
.MoveNext
Loop
End With
Set oMail = Nothing
Set oLook = Nothing
Err_email_exp1_Click:
MsgBox Err.Description
Resume Exit_email_exp1_Click
End Sub
Many thanks in advance.
Paul
I am trying to add an attachment to an email from email addresses that are generated from a query in Access. I've tried to amalgamate to pieces of code to form one but I am getting the Complie Error: 'End If without block If' message. I'd really appreciate it if someone could cast their expert eye over the code below and see if they can find a solution.
Private Sub email_exp1_Click()
On Error GoTo Err_email_exp1_Click
Dim MyDb As DAO.Database
Dim rsEmail As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim strEmail As String
Dim strMsg As String
Dim oLook As Object
Dim oMail As Object
Set MyDb = CurrentDb
Set qdf = MyDb.QueryDefs("qryexp_may11")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next
Set rsEmail = qdf.OpenRecordset()
Set oLook = CreateObject("Outlook.Application")
With rsEmail
.MoveFirst
Do Until rsEmail.EOF
If IsNull(.Fields(0)) = False Then
Set oMail = oLook.createitem(0)
With oMail
.to = .Fields(0)
.body = "See attached"
.Subject = "Is the file attached"
.Attachments.Add("\\mynetwork\mynetworkfolder\example.doc")
.Send
End If
.MoveNext
Loop
End With
Set oMail = Nothing
Set oLook = Nothing
Err_email_exp1_Click:
MsgBox Err.Description
Resume Exit_email_exp1_Click
End Sub
Many thanks in advance.
Paul