Outlook Tasks - I thought I had it but somethings wrong

G

Gina Whipp

Hello All,
The below errors out (see arrow). Please tell me what I am doing wrong...

***Declarations***
Public olTaskItem As Object
Public OutlookTask As Object


***In the InitializeOutlook() section
Set OutlookTask = golApp.CreateItem(olTaskItem)

***Function Start***
Function fncAddOutlookTask(frm As Form)
' Set global Application and NameSpace
' object variables, if necessary.
If golApp Is Nothing Then
If InitializeOutlook = False Then
MsgBox "Unable to initialize Microsoft Outlook!"
End If
End If

Dim OutlookTask As TaskItem <---- Undefined

With OutlookTask
.Subject = frm!txtSubject
.Body = frm!txtNotes
.ReminderSet = True
'Remind 2 minutes from now.
.ReminderTime = DateAdd("n", 2, Now)
'Due 5 minutes from now.
.DueDate = DateAdd("n", 5, Now)
.ReminderPlaySound = True
'Modify path.
.ReminderSoundFile = "C:\WINNT\Media\Ding.wav"
.Save
End With
End Function
***Function End***

Thanks for any and all help...
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II
 
R

Robert Morley

I don't think you even need that line at all...you've got "Public
OutlookTask As Object" earlier in the code.

In any event, probably the problem is that you don't have a reference to the
Outlook library in Tools, References.



Rob
 
R

Robert Morley

It's probably not the entire problem, but try moving the Set OutlookTask
line from InitializeOutlook to just before the With OutlookTask line. I can
see some potential problems occurring there, though like I say, I don't
think that's the entire thing.

There's nothing obviously wrong with the .Subject line...are you sure frm is
defined, and there's a control on the form called txtSubject?



Rob
 
G

Gina Whipp

I got it!!!

Below is what I ended with...

I'm not even sure what I did because I've been playing with this code so
much. Thank you Robert for your suggestions. And Thanks to Danny J.
Lesandrini whose code helped me find the problem.

Const olTaskItem = 3
Public objTask As Object

Function fncAddOutlookTask(frm As Form)

If Err.Number = 429 Then
Set golApp = CreateObject("Outlook.Application", "LocalHost") '
Application object
End If

Dim objTask
Set objTask = golApp.CreateItem(olTaskItem)

With objTask
.Subject = frm!txtSubject
.Body = frm!txtNotes
.ReminderSet = True
'Remind 2 minutes from now.
.ReminderTime = DateAdd("n", 2, Now)
'Due 5 minutes from now.
.DueDate = frm!txtDueDate
.ReminderPlaySound = True
'Modify path.
.ReminderSoundFile = "C:\WINNT\Media\Ding.wav"
.Save
End With
 

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