Reminders

J

jimAH

Hi all,

I've created a custom form based on the standard contact form which allows
users to log information about a particular piece of hardware they may be
using. One of the fields contains the users email address. What I'd like to
do is once a week send out a reminder to those who have hardware in their
name so they can help keep things up to date. Any clues on how much
appreciated. The form is located in one of our public folders if that helps.

Thanks!
James
 
E

Eric Legault [MVP - Outlook]

The code below should set you on your way with a little modification. If you
run the SendNotifications procedure, it will loop through the specified
Public Folder and look for items with a specific value for the specified
custom field. If it matches, it will take the value of another custom field
(e.g. an e-mail address) and create and send a new e-mail message to that
person. Change the message type or message data (e.g. Subject, Body) as you
see fit for your solution.

The other function is used to retrieve a specific folder object by using the
full path to that folder.

Sub SendNotifications()
On Error GoTo SendNotifications_Error

Dim objFolder As Outlook.MAPIFolder
Dim objContact As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim objResults As Outlook.Items
Dim objNewMail As Outlook.MailItem
Dim intX As Integer

Set objFolder = OpenMAPIFolder("\\Public Folders\All Public
Folders\FOLDER NAME")
Set objItems = objFolder.Items

Set objResults = objItems.Restrict("[MyCustomField] = 'expected value'")
'make sure this custom field is published to the folder and not just the
custom form
'so that it is available for the Resrict method to use

For intX = 1 To objResults.Count
If objResults.Item(intX).MessageClass = "IPM.MyCustomFormName" Then
Set objContact = objResults.Item(intX)
Set objNewMail = Application.CreateItem(olMailItem)
objNewMail.Subject = "My subject"
objNewMail.Body = "My message body"
objNewMail.To = objContact.UserProperties("MyCustomField2").Value
objNewMail.Send
End If
Next

Set objFolder = Nothing
Set objResults = Nothing
Set objItems = Nothing
Set objNewMail = Nothing

On Error GoTo 0
Exit Sub

SendNotifications_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
SendNotifications of Module Module1"
Resume Next
End Sub


'******************************************************************************
'Custom procedure: OpenMAPIFolder(ByVal strPath)
'Purpose: Return a MAPIFolder from Path argument
'Returns: MAPIFolder object
'******************************************************************************
Function OpenMAPIFolder(ByVal strPath) As Outlook.MAPIFolder
On Error Resume Next

Dim objFldr As MAPIFolder
Dim strDir As String
Dim strName As String
Dim i As Integer
If Left(strPath, Len("\")) = "\" Then
strPath = Mid(strPath, Len("\") + 1)
Else
Set objFldr = Application.ActiveExplorer.CurrentFolder
End If
While strPath <> ""
i = InStr(strPath, "\")
If i Then
strDir = Left(strPath, i - 1)
strPath = Mid(strPath, i + Len("\"))
Else
strDir = strPath
strPath = ""
End If
If objFldr Is Nothing Then
Set objFldr = Application.GetNamespace("MAPI").Folders(strDir)
On Error GoTo 0
Else
Set objFldr = objFldr.Folders(strDir)
End If
Wend
Set OpenMAPIFolder = objFldr
End Function
 
J

jimAH

Thanks Eric - I'll try this out.

In order to send messages out on a regular basis, say every Wednesday at
12pm, would you use some form of integration with Task Scheduler?

Thanks again,
James

Eric Legault said:
The code below should set you on your way with a little modification. If you
run the SendNotifications procedure, it will loop through the specified
Public Folder and look for items with a specific value for the specified
custom field. If it matches, it will take the value of another custom field
(e.g. an e-mail address) and create and send a new e-mail message to that
person. Change the message type or message data (e.g. Subject, Body) as you
see fit for your solution.

The other function is used to retrieve a specific folder object by using the
full path to that folder.

Sub SendNotifications()
On Error GoTo SendNotifications_Error

Dim objFolder As Outlook.MAPIFolder
Dim objContact As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim objResults As Outlook.Items
Dim objNewMail As Outlook.MailItem
Dim intX As Integer

Set objFolder = OpenMAPIFolder("\\Public Folders\All Public
Folders\FOLDER NAME")
Set objItems = objFolder.Items

Set objResults = objItems.Restrict("[MyCustomField] = 'expected value'")
'make sure this custom field is published to the folder and not just the
custom form
'so that it is available for the Resrict method to use

For intX = 1 To objResults.Count
If objResults.Item(intX).MessageClass = "IPM.MyCustomFormName" Then
Set objContact = objResults.Item(intX)
Set objNewMail = Application.CreateItem(olMailItem)
objNewMail.Subject = "My subject"
objNewMail.Body = "My message body"
objNewMail.To = objContact.UserProperties("MyCustomField2").Value
objNewMail.Send
End If
Next

Set objFolder = Nothing
Set objResults = Nothing
Set objItems = Nothing
Set objNewMail = Nothing

On Error GoTo 0
Exit Sub

SendNotifications_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
SendNotifications of Module Module1"
Resume Next
End Sub


'******************************************************************************
'Custom procedure: OpenMAPIFolder(ByVal strPath)
'Purpose: Return a MAPIFolder from Path argument
'Returns: MAPIFolder object
'******************************************************************************
Function OpenMAPIFolder(ByVal strPath) As Outlook.MAPIFolder
On Error Resume Next

Dim objFldr As MAPIFolder
Dim strDir As String
Dim strName As String
Dim i As Integer
If Left(strPath, Len("\")) = "\" Then
strPath = Mid(strPath, Len("\") + 1)
Else
Set objFldr = Application.ActiveExplorer.CurrentFolder
End If
While strPath <> ""
i = InStr(strPath, "\")
If i Then
strDir = Left(strPath, i - 1)
strPath = Mid(strPath, i + Len("\"))
Else
strDir = strPath
strPath = ""
End If
If objFldr Is Nothing Then
Set objFldr = Application.GetNamespace("MAPI").Folders(strDir)
On Error GoTo 0
Else
Set objFldr = objFldr.Folders(strDir)
End If
Wend
Set OpenMAPIFolder = objFldr
End Function

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


jimAH said:
Hi all,

I've created a custom form based on the standard contact form which allows
users to log information about a particular piece of hardware they may be
using. One of the fields contains the users email address. What I'd like to
do is once a week send out a reminder to those who have hardware in their
name so they can help keep things up to date. Any clues on how much
appreciated. The form is located in one of our public folders if that helps.

Thanks!
James
 
E

Eric Legault [MVP - Outlook]

No, running Outlook via the Task Scheduler is not typically supported. I
would hook into the ReminderFire event and look for the name of a special
Task that you create to automate this process, and fire the process if this
is the reminder for this Task. You still need to have Outlook running for
this to work though. Otherwise, you are looking at a server-side solution or
using CDO.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


jimAH said:
Thanks Eric - I'll try this out.

In order to send messages out on a regular basis, say every Wednesday at
12pm, would you use some form of integration with Task Scheduler?

Thanks again,
James

Eric Legault said:
The code below should set you on your way with a little modification. If you
run the SendNotifications procedure, it will loop through the specified
Public Folder and look for items with a specific value for the specified
custom field. If it matches, it will take the value of another custom field
(e.g. an e-mail address) and create and send a new e-mail message to that
person. Change the message type or message data (e.g. Subject, Body) as you
see fit for your solution.

The other function is used to retrieve a specific folder object by using the
full path to that folder.

Sub SendNotifications()
On Error GoTo SendNotifications_Error

Dim objFolder As Outlook.MAPIFolder
Dim objContact As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim objResults As Outlook.Items
Dim objNewMail As Outlook.MailItem
Dim intX As Integer

Set objFolder = OpenMAPIFolder("\\Public Folders\All Public
Folders\FOLDER NAME")
Set objItems = objFolder.Items

Set objResults = objItems.Restrict("[MyCustomField] = 'expected value'")
'make sure this custom field is published to the folder and not just the
custom form
'so that it is available for the Resrict method to use

For intX = 1 To objResults.Count
If objResults.Item(intX).MessageClass = "IPM.MyCustomFormName" Then
Set objContact = objResults.Item(intX)
Set objNewMail = Application.CreateItem(olMailItem)
objNewMail.Subject = "My subject"
objNewMail.Body = "My message body"
objNewMail.To = objContact.UserProperties("MyCustomField2").Value
objNewMail.Send
End If
Next

Set objFolder = Nothing
Set objResults = Nothing
Set objItems = Nothing
Set objNewMail = Nothing

On Error GoTo 0
Exit Sub

SendNotifications_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
SendNotifications of Module Module1"
Resume Next
End Sub


'******************************************************************************
'Custom procedure: OpenMAPIFolder(ByVal strPath)
'Purpose: Return a MAPIFolder from Path argument
'Returns: MAPIFolder object
'******************************************************************************
Function OpenMAPIFolder(ByVal strPath) As Outlook.MAPIFolder
On Error Resume Next

Dim objFldr As MAPIFolder
Dim strDir As String
Dim strName As String
Dim i As Integer
If Left(strPath, Len("\")) = "\" Then
strPath = Mid(strPath, Len("\") + 1)
Else
Set objFldr = Application.ActiveExplorer.CurrentFolder
End If
While strPath <> ""
i = InStr(strPath, "\")
If i Then
strDir = Left(strPath, i - 1)
strPath = Mid(strPath, i + Len("\"))
Else
strDir = strPath
strPath = ""
End If
If objFldr Is Nothing Then
Set objFldr = Application.GetNamespace("MAPI").Folders(strDir)
On Error GoTo 0
Else
Set objFldr = objFldr.Folders(strDir)
End If
Wend
Set OpenMAPIFolder = objFldr
End Function

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


jimAH said:
Hi all,

I've created a custom form based on the standard contact form which allows
users to log information about a particular piece of hardware they may be
using. One of the fields contains the users email address. What I'd like to
do is once a week send out a reminder to those who have hardware in their
name so they can help keep things up to date. Any clues on how much
appreciated. The form is located in one of our public folders if that helps.

Thanks!
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top