Outlook Task from Access

G

Guest

Hi.

I have a client contact database in Access 2003 and I am looking to create
an Outlook TaskItem as a reminder for myself or assiged to another user.

I've been able to use the following code (downloaded from the MS website)
with success however, I would like to populate the '.body' with the details
of the call. I have several fields setup with ContactName, Company, Products,
Notes etc and I would like these to form the basis of a detailed reminder
system for our users

Here is the code that I have used (tailored slightly for our purposes)...

Option Compare Database
Option Explicit

Function fncAddOutlookTask()
Dim OutlookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem

Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookTask = OutlookApp.CreateItem(olTaskItem)

With OutlookTask
.Subject = "This is the subject of my task"
.Body = "This is the body of my task."
.ReminderSet = True
.ReminderTime = DateAdd("n", 2, Now) 'Remind 2 minutes from now.
.DueDate = DateAdd("n", 5, Now) 'Due 5 minutes from now.
.ReminderPlaySound = True
.ReminderSoundFile = "C:\Windows\Media\Ding.wav" 'Modify path.
.Save
End With
End Function

Can someone point me in the right direction as to how to get multiple lines
to be contained within the task.

Thanks in advance.
 
G

Guest

Thanks Tom, that worked well.

Being new to this (I'm not a VBA guy at all), I'm wondering, can this be
written as a 'sub routine' as opposed to a function? I'm thinking that it
would be easier to incorporate in my present code as such.

If you have a spare moment, I'd appreciate your input as I am trying to
understand the differences.

Many thanks,

Mark
 
G

Guest

Hi Mark,
I'm wondering, can this be written as a 'sub routine' as opposed to a function?
Yes, it can be, as long as you are not calling it from a macro.
I'm thinking that it would be easier to incorporate in my present code as such.
Why would it be any easier?

A function is used to return a value, whereas a subroutine just carries out
an action (like sending an e-mail). The function that you currently have:

Function fncAddOutlookTask()

does not include a return value. In fact, this function would be flagged by
Total Access Analyzer (http://www.fmsinc.com/products/analyzer/index.html)
for not including a return value. Here is the exact text of this error, as
flagged by Total Access Analyzer (version 10.5):

<Begin Quote>
Module Function Not Assigned a Return Value
This function is not assigned a return value. If the function is called by a
routine that expects a value, the wrong value or no value is returned.
Procedures that don't return a value can be defined as a Sub instead of a
Function. There are some situations, like calls from macros, where the
procedure called needs to be defined as a function, in which case this is not
a problem. Otherwise, fix the function to return a value."
</End Quote>

An example of returning a value would include the following:

Function fncAddOutlookTask() As Boolean

Here, the function returns a boolean value (true or false) depending on some
condition within the function.


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

:

Thanks Tom, that worked well.

Being new to this (I'm not a VBA guy at all), I'm wondering, can this be
written as a 'sub routine' as opposed to a function? I'm thinking that it
would be easier to incorporate in my present code as such.

If you have a spare moment, I'd appreciate your input as I am trying to
understand the differences.

Many thanks,

Mark

__________________________________________

:

Hi Mark,

You can use VBA code to build up a string, which you can then use in the
line of code where you are setting the .body value. Something like this:

Dim strBodyText as String

strBodyText = Nz(ContactName + vbCrLf, "") & Nz(Company + vbCrLf, "") _
& Nz(Products + vbCrLf, "") & Nz(Notes, "")

followed by:

With OutlookTask
.Subject = "This is the subject of my task"
.Body = strBodyText


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

:

Hi.

I have a client contact database in Access 2003 and I am looking to create
an Outlook TaskItem as a reminder for myself or assiged to another user.

I've been able to use the following code (downloaded from the MS website)
with success however, I would like to populate the '.body' with the details
of the call. I have several fields setup with ContactName, Company, Products,
Notes etc and I would like these to form the basis of a detailed reminder
system for our users

Here is the code that I have used (tailored slightly for our purposes)...

Option Compare Database
Option Explicit

Function fncAddOutlookTask()
Dim OutlookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem

Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookTask = OutlookApp.CreateItem(olTaskItem)

With OutlookTask
.Subject = "This is the subject of my task"
.Body = "This is the body of my task."
.ReminderSet = True
.ReminderTime = DateAdd("n", 2, Now) 'Remind 2 minutes from now.
.DueDate = DateAdd("n", 5, Now) 'Due 5 minutes from now.
.ReminderPlaySound = True
.ReminderSoundFile = "C:\Windows\Media\Ding.wav" 'Modify path.
.Save
End With
End Function

Can someone point me in the right direction as to how to get multiple lines
to be contained within the task.

Thanks in advance.
 
G

Guest

Thanks Tom,

That helps a lot and I'll be taking a look at the tool you referred to.

Some people would have referred me to a book and I thank you for taking the
time to respond.

Cheers,
 
G

Guest

Hi Mark,

You're welcome. While I have no business relationship with FMS, I
wholeheartedly endorse several of their products, including Total Access
Analyzer and Total Access Detective, to name a few. These products are well
worth the costs if you spend any significant amount of time developing with
Access.

Tom
____________________________________________

:

Thanks Tom,

That helps a lot and I'll be taking a look at the tool you referred to.

Some people would have referred me to a book and I thank you for taking the
time to respond.

Cheers,
 

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