Code Examples

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Hi



Has any one got any VBA code examples that would fulfil the following:-

(Outlook 2003 used in Access 2003)





Open outlook if it is not running if open don't open 2nd copy and Send task
out to a recipient and Make the task a recurrence task.



Thank you for any assistance.



Dave
 
Try this code:

Dim objOL As Outlook.Application, blnNewOutlook As Boolean
Dim objExp As Outlook.Explorer
Dim objNS As Outlook.NameSpace
Dim objTask As Outlook.TaskItem
Dim myDelegate As Outlook.Recipient
Dim myPattern As Outlook.RecurrencePattern

'Retrieve an existing Outlook Application object if it is already loaded
Set objOL = GetObject(, "Outlook.Application")
If objOL Is Nothing Then
'Outlook is closed; open it
Set objOL = New Outlook.Application
blnNewOutlook = True
End If
Set objNS = objOL.GetNamespace("MAPI")

If blnNewOutlook = True Then
Set objExp =
objOL.Explorers.Add(objNS.GetDefaultFolder(olFolderInbox),
olFolderDisplayNormal)
objExp.Activate 'Show Outlook
End If

Set objTask = objOL.CreateItem(olTaskItem)
objTask.Assign

Set myDelegate = objTask.Recipients.Add("Dan Wilson") 'will trigger
Object Model Guard from outside of Outlook
myDelegate.Resolve
If myDelegate.Resolved Then
objTask.Subject = "Prepare Agenda For Meeting"
Set myPattern = objTask.GetRecurrencePattern
objTask.DueDate = Now + 30
myPattern.RecurrenceType = olRecursMonthly
myPattern.Regenerate = True
myPattern.Interval = 3
objTask.Display
objTask.Send 'will trigger Object Model Guard from outside of Outlook
End If

Set objTask = Nothing

If blnNewOutlook = True Then
objExp.Close
objOL.Quit
End If

Set myDelegate = Nothing
Set myPattern = Nothing
Set objExp = Nothing
Set objNS = Nothing
Set objOL = Nothing
 
Hi, Eric

Thank you for the example. Unfortunately when ran I got a runtime error 429
active x component can't create object with " Set objOL = GetObject(,
"Outlook.Application") " highlighted thinking that a typo had got in I
updated the line to read Set objOL = GetObject("Outlook.Application") but I
now get a automation error, could you help?


Dave
 
Go the Tools - References dialog in the Access VBA editor and select
"Microsoft Outlook 11.0 Object Library". Declaring variables for COM objects
requires that the appropriate library is made available in order to use them
"by name". For example, declaring "objOL As Outlook.Application" is drawing
from that object library so that Intellisense can tell you which properties,
methods, etc. are available for the objects you are using. Otherwise, you'd
need to declare object variables "As Object", but you'd get no Intellisene
and the VBA Runtime engine would have to determine what these objects are
when the code is actually run.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/
 
Am Fri, 30 Jun 2006 20:23:06 GMT schrieb Dave:

It´s not a typo. Please turn back to
Set objOL = GetObject(, "Outlook.Application")

An error at that line is normal behaviour if the application isn´t running.
To ignore that error simply add "On Error Resume Next" before calling
GetObject.
 
Hi,Eric &Viele

Thank you again for your help
Eric, I did have the "Microsoft Outlook 11.0 Object Library" selected.

Viele, Replacing the code as Eric had stated and adding the "On Error Resume
Next" got me up and running.

If I could ask for you help on this final part. I would like to attach a
Access snapshot file as a task attachment I understand that I could use the
DoCmd.OutputTo acOutputReport, "PS_Report", acFormatSNP, "PS_Report.snp",
True statement how would I integrate this in to your example.

Thank you again for your time.

Dave
 
For any Outlook item, file attachments are inserted using the
*Item.Attachments.Add method, with the path to the desired file used as an
argument:

Sub AddAttachment()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\Test.doc", _
olByValue, 1, "Test"
myItem.Display
End Sub
 
Back
Top