Thank you for your reply Mile,
I have been getting no errors at all. With regards to the weird table name that is because somebody setup a wholesaler targets file and decided to call it that, I have no idea why and do not want to change it as so many people seem to link into it.
As I was saying I got no errors so thought I would try and put the email code in. The following is the code I hope to get working to automatically send out emails and attachments. I have also added the error message I get when running this new code.
"Either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record."
Option Compare Database
Private Sub Email_Click()
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim CICODE As String
Set conn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.Open "SELECT [Target_June2003].[CI Code], [Target_June2003].[Business Manager], [Target_June2003].Active " & _
"FROM [Target_June2003] WHERE ((([Target_June2003].Active)=True));", conn, adOpenDynamic
rst.MoveFirst
Do While Not rst.EOF And Not rst.BOF
CICODE = rst![CI Code]
'Me.test = CICODE
'Email code
Dim conn1 As ADODB.Connection
Dim rst1 As ADODB.Recordset
Dim Originator As String
Set conn1 = CurrentProject.Connection
Set rst1 = New ADODB.Recordset
Dim Attachment As String
Dim AttachME As Object 'The attachment richtextfile object
Dim EmbedObj As Object 'The embedded object (Attachment)
Dim EmailSend As Object
Dim EmailApp As Object
rst1.Open "SELECT MasterWholesaler.ci_code, MasterWholesaler.Email1, MasterWholesaler.email2 From MasterWholesaler " & _
"WHERE ([MasterWholesaler.ci_code])= '" & CICODE & "' ;", conn1, adOpenForwardOnly, adLockReadOnly, adCmdTableDirect
'Array for multiple addresses
Dim recip(2) As Variant
recip(0) = rst1!Email1
recip(1) = rst1!Email2
'EmailAddress = rst!email_address
Dim s As Object
Dim db As Object
Dim doc As Object
Dim rtItem As Object
Dim Server As String, Database As String
Dim strError As String
Set s = CreateObject("Notes.notesSession")
Server = s.GETENVIRONMENTSTRING("MailServer", True)
Database = s.GETENVIRONMENTSTRING("MailFile", True)
Set db = s.GETDATABASE(Server, Database)
'see if user is logged on
Set doc = db.CREATEDOCUMENT
'On Error GoTo 0
doc.Form = "Memo"
doc.importance = "1" '(Where 1=Urgent, 2= Normal, 3= FYI)
doc.sendto = recip ' Used for multiple addresses see array above
doc.RETURNRECEIPT = "1"
doc.Subject = "CBA report for - " & Originator
Set rtItem = doc.CreateRichTextItem("Body")
Call rtItem.APPENDTEXT("Dear Parts Manager,")
Call rtItem.ADDNEWLINE(2)
Call rtItem.APPENDTEXT("Please find attached this weeks CBA report for - ")
Call rtItem.ADDNEWLINE(2)
Call rtItem.APPENDTEXT("Kind Regards")
Call rtItem.ADDNEWLINE(2)
Call rtItem.APPENDTEXT("MG Rover Communications")
'Set AttachME = MailDoc.CreateRichTextItem.Add("C:\Documents and Settings\szymkm\Desktop\test.txt")
'Set EmbedObj = AttachME.EmbedObject(1454, "", "C:\Documents and Settings\szymkm\Desktop\test.txt")
Set AttachME = doc.CreateRichTextItem("C:\Documents and Settings\szymkm\Desktop\" & CICODE & ".txt")
Set EmbedObj = AttachME.EmbedObject(1454, "", "C:\Documents and Settings\szymkm\Desktop\" & CICODE & ".txt")
Call doc.Send(False)
Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing
rst1.Close
ErrorLogon:
If Err.Number = 7063 Then
MsgBox " You must first logon to Lotus Notes"
ElseIf Err.Number = 7000 Then
MsgBox "There is no email address for " & CICODE
End If
rst.MoveNext
Loop
rst.Close
End Sub
Thanks again for your help
Mark