User Defined not defind

  • Thread starter Looping through
  • Start date
L

Looping through

I have a question.

How do you define the following

Sub CreateTask()

Dim olApp As Outlook.Application
Dim olTsk As TaskItem

Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)

With olTsk
.Subject = "Update Web Site"
.Status = olTaskInProgress
.Importance = olImportanceHigh
.DueDate = DateValue("06/26/03")
.TotalWork = 40
.ActualWork = 20
.Save
End With

Set olTsk = Nothing
Set olApp = Nothing

End Sub

When I run this code I get an error stating "User-Definded type not defined"

Pete
 
P

Peter T

With "Early Binding" to Outlook you need to "check" the reference to MS
Outlook in Tools - References. Alternatively you can switch to "Late
Binding" with the following changes to your code

Dim olApp As Object ' Outlook.Application
Dim olTsk As Object ' TaskItem

Set olApp = CreateObject("outlook.application") ' New Outlook.Application
'code
..Status = 1 ' olTaskInProgress
..Importance = 2 ' olImportanceHigh
'code

If there is any possibility of a user of your file having an older version
of Outlook than yours, use the Late Binding method.

Regards,
Peter T
 
L

Looping through

Thanks Peter T.

I made you suggested changes and get a run time error 438 "Object does not
support this property or method" Maybe I did not change everything exactly
like you intended.

Here is my revised code.

Sub CreateTask_test()

Dim olApp As Object
Dim olTsk As Object

Set olApp = CreateObject("outlook.application") ' New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)

With olTsk
.Subject = "Update Web Site"
.Status = 1 ' olTaskInProgress
.Importance = 2 ' olImportanceHigh
.DueDate = DateValue("06/26/03")
.TotalWork = 40
.ActualWork = 20
.Save
End With
Set olTsk = Nothing
Set olApp = Nothing
End Sub

What did I miss.
Peter
 
P

Peter T

I didn't test so I might have missed something. Best approach is to develop
with "Early Binding", then change to "Late Binding" if any user might not
have as late a version as your Outlook installed.

So for testing set the reference as I suggested last time and test your
original code. Head the module "Option Explicit" without quotes, anything
incorrect will be highlit as soon as you start to run the routine. When all
appears OK, adapt to Late Binding along the lines I suggested, if I missed
something it'll soon become apparent and hopefully obvious what else needs
changing

Regards,
Peter T
 
L

Looping through

The following line gets an Compile Error "Varible Not defined"
Set olTsk = olApp.createitem(OLTaskitem)

Peter
 
P

Peter T

Did it all work with the reference to Outlook (early binding). ?

Set the OL reference. in Tools - Ref's

In the immediate window, ctrl-g, place the cursor after
?OLTaskitem
and hit enter

remember, first set the reference to OL.
You should find the constant value for OLTaskitem in the OL library is 3

Revert to Late Binding (if you really need to do it that way) and change
Set olTsk = olApp.createitem(OLTaskitem)
to
Set olTsk = olApp.createitem(3) ' OLTaskitem

Do similar for any other constants I may have missed (I still haven't tested
it).

Regards,
Peter T
 
D

Dave Peterson

OLTaskitem didn't get changed to a constant like these did:


If you open Outlook, go into the VBE, you can hit ctrl-g to see the immediate
window.

Then type:
?OLTaskitem

And you'll see that this is equal to 3.


so this:
Set olTsk = olApp.CreateItem(olTaskItem)
becomes:
Set olTsk = olApp.CreateItem(3)
 

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