L
Larry Bitler
Is there any way to set the code so the emails will be
sent automaticaly without keyboard interaction.
This is the code I am using:
Option Compare Database
Option Explicit
Private Sub Form_Open(Cancel As Integer)
Dim dbs As Database
Dim rst As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim MyBodyText As String
'Set the Subjectline
Subjectline = "Your Current PTO Time Available"
'Set the application
Set MyOutlook = New Outlook.Application
'Set up the database and query connections
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("MyEmailAddresses",
dbOpenDynaset)
'Set up emails
Do Until rst.EOF
Set MyMail = MyOutlook.CreateItem(olMailItem)
MyMail.To = rst!email
MyMail.Subject = Subjectline
MyMail.Body = "Your current PTO is " + rst!PTO + "
hours."
MyMail.Send
rst.MoveNext
Loop
'Cleanup
Set MyMail = Nothing
MyOutlook.Quit
Set MyOutlook = Nothing
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
End Sub
Any help would be greatly appreciated.
sent automaticaly without keyboard interaction.
This is the code I am using:
Option Compare Database
Option Explicit
Private Sub Form_Open(Cancel As Integer)
Dim dbs As Database
Dim rst As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim MyBodyText As String
'Set the Subjectline
Subjectline = "Your Current PTO Time Available"
'Set the application
Set MyOutlook = New Outlook.Application
'Set up the database and query connections
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("MyEmailAddresses",
dbOpenDynaset)
'Set up emails
Do Until rst.EOF
Set MyMail = MyOutlook.CreateItem(olMailItem)
MyMail.To = rst!email
MyMail.Subject = Subjectline
MyMail.Body = "Your current PTO is " + rst!PTO + "
hours."
MyMail.Send
rst.MoveNext
Loop
'Cleanup
Set MyMail = Nothing
MyOutlook.Quit
Set MyOutlook = Nothing
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
End Sub
Any help would be greatly appreciated.