Hey guys,
If anyone could spare sometime to help me out, it would be very much
appreciated.....what I am trying to do is automate a "Command" that
sends me an Email. I have created a Query that grabs all the records I
am after...now all I need to do is get some code that will allow me
loop through each of these records shown by the query and pass certain
fields from these records into the Body of my email command...which
then emails itself to one person, and that person being myself.
The Email command I have at the moment, is as follows:
Sub SendMail(strTo)
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String
Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olMail As Outlook.MailItem
strsubject = "ATTN:Shore-Based Maintainance Agreements"
varbody = fMsgBody
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
olNs.Logon
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = strTo
olMail.Subject = strsubject
olMail.Body = fMsgBody
olMail.Send
Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing
End Sub
I just need some code to automate the above with the fields from the
records passed into the Body of the email....so far I have this......
Private Sub SBMACheckAndEmail_Click()
Dim rst As DAO.Recordset
Dim strList As String
Set rst = DBEngine(0)(0).OpenRecordset("qryEmail")
Do Until rst.EOF
strList = rst.Fields("SMBA Number") & " " & rst.Fields("Vessel
Name") & "" & rst.Fields("IMO Number") & "" & rst.Fields("Date of
Issue") & vbCrLf
SendMail ("ga************@hotmail.com")
rst.MoveNext
Loop
fMsgBody = "The following accounts are due:" & vbCrLf & strList
rst.Close
Set rst = Nothing
End Function
End Sub
If someone could point me in the right direction it would be very much
appreciated
Kind Regards