Page 1 of 1

To Antonio : my Outlook problem

Posted: Fri Jun 13, 2008 2:01 pm
by driessen
Hello Antonio,

Thanks for your help until now.

As you asked me to, I'll continue our conversation here.

After your advice of last Wednesday, I tried this code today :

Code: Select all

oOutlook         := CreateObject("Outlook.Application")
oNameSpace       := oOutlook:GetNameSpace("MAPI")
oCalendar        := oNameSpace:GetDefaultFolder(outlookFolderCalendar)
oItem            := oOutlook:CreateItem(1)

oItem:Start      := DTOC(AG->AGDATUM) + " " + AG->AGBTIJD
oItem:StartTime  := AG->AGBTIJD + ":00"
oItem:Duration   := Ol1Minuut * 60
oItem:Subject    := ALLTRIM(IF(VAL(AG->AGSRTNR)=0,AG->AGSRTNRN,AG->AGOMSCH))
oItem:Body       := ALLTRIM(cOUTLOMSCH)
oItem:Category   := IF(VAL(AG->AGSRTNR)<=0,"Rechtbank",AG->AGSRTNRN)
oItem:Location   := ALLTRIM(AG->AGVERGNRN)
oItem:Importance := ExPrior
IF AG->ALARM
	oItem:ReminderMinutesBeforeStart := cOl2Minuut * 60
	oItem:ReminderSet := cTRUE
ELSE
  	oItem:ReminderSet := cFALSE
ENDIF
oItem:Save()

oCalendar  := NIL
oNameSpace := NIL
oOutlook   := NIL
oItem      := NIL
Unfortunately the result isn't good.

On line 3 I already get a GPF and my application is closed.

What now ?

Thanks a lot.

Regards.

Posted: Fri Jun 13, 2008 2:45 pm
by NK
Test this sample

Code: Select all

FUNCTION AddOLCalendar( cDate, cTime, nDuration, cTitle, cMemo )

   LOCAL hOutlook
   LOCAL hApptItem
   LOCAL nFolderNr
   hOutlook  := CreateOLEObject( "Outlook.Application" )
   hAppItem  := OLEInvoke( hOutlook, "CreateItem", 1 )
   OLESetProperty( hAppItem, "Start", cDate + " " + cTime )
   OLESetProperty( hAppItem, "StartTime", cTime + ":00" )
   OLESetProperty( hAppItem, "Duration", nDuration * 60 )
   OLESetProperty( hAppItem, "Subject", cTitle )
   OLESetProperty( hAppItem, "Body", cMemo )
   OLESetProperty( hAppItem, "Mileage", 225 )
   OLEInvoke( hAppItem, "Save" )
   hAppItem := NIL
   hOutlook := NIL
RETURN NIL
Regards, Norbert

Posted: Fri Jun 13, 2008 3:30 pm
by driessen
Norbert,

Thanks for your reply.

Your example doesn't give any errors, but ... I don't find my appointments in Outlook unfortunately.

Any idea why I don't ?

Thanks.

Regards.

Posted: Fri Jun 13, 2008 4:09 pm
by James Bott
Michel,

Here is a sample I found in my notes. I have not tried it.

James

Code: Select all

FUNCTION AddOLappointment( cDate, cTime, nLenInMin, cSubject, cNotiz ) 

   LOCAL hOutlook 
   LOCAL hApptItem 
   LOCAL dDate 
   LOCAL lSave := .F. 
   TRY 
      hOutlook  := CreateOLEObject( "Outlook.Application" ) 
      hAppItem  := OLEInvoke( hOutlook, "CreateItem", 1 ) 

      SET CENTURY ON 
      dDate := CToD( cDate ) 
      OLESetProperty( hAppItem, "Start", cDate + " " + cTime ) 
      OLESetProperty( hAppItem, "StartTime", cTime + ":00" ) 
      SET CENTURY ON 
      SET Date TO GERMAN 
      OLESetProperty( hAppItem, "Duration", nLenInMin * 60 ) 
      OLESetProperty( hAppItem, "Subject", cSubject ) 
      OLESetProperty( hAppItem, "Body", cNotiz ) 
      OLESetProperty( hAppItem, "Mileage", 225 ) 
      OLEInvoke( hAppItem, "Save" ) 
      hAppItem := NIL 
      hOutlook := NIL 
      lSave := .t. 
   CATCH 
      lSave := .f. 
   END 
RETURN (lSave) 

Posted: Fri Jun 13, 2008 4:24 pm
by Otto
Michel,
Are you working with version 2007?
I face the same problem but only if Outlook is closed. If I open Outlook first all works.


Regards,
Otto

Posted: Fri Jun 13, 2008 10:59 pm
by driessen
Otto,
James,
Norbert,

Thanks for your help.

I am able to add items to the calendar, but also tasks, in Outlook.

What did I change :

1. You need to use CreateOLEObject() in stead of CreateObject().
2. No use of GetNameSpace()
3. In case of Outlook 2007, Outlook has to be opened, just like Otto said.

The Outlook 2007 problem, I solved by searching for "OUTLOOK" in the array Gettasks().

If Outlook isn't found, I do this :

Code: Select all

WINEXEC(cOUTPATH,2)
where cOUTPATH contains the pathname of OUTLOOK.EXE.

Is there another way to launch Outlook ?

Thanks.

Regards.

Posted: Sat Jun 14, 2008 8:24 am
by Antonio Linares
Michel,

Many thanks for your feedback,

WinExec() is fine. Another way may be ShellExecute() (not tested).

Posted: Sat Jun 14, 2008 12:31 pm
by Enrico Maria Giordano
driessen wrote:1. You need to use CreateOLEObject() in stead of CreateObject().
I strongly recommend CreateObject() as it allows the easier syntax

Code: Select all

oOutlook:CreateItem(1)
EMG