To Antonio : my Outlook problem

Post Reply
User avatar
driessen
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

To Antonio : my Outlook problem

Post 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 | Expand

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.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
NK
Posts: 97
Joined: Sun Nov 20, 2005 4:32 pm
Location: Germany
Contact:

Post by NK »

Test this sample

Code: Select all | Expand

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
User avatar
driessen
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post 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.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Michel,

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

James

Code: Select all | Expand

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)
User avatar
Otto
Posts: 6400
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 9 times
Been thanked: 2 times
Contact:

Post 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
User avatar
driessen
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Post 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 | Expand

WINEXEC(cOUTPATH,2)

where cOUTPATH contains the pathname of OUTLOOK.EXE.

Is there another way to launch Outlook ?

Thanks.

Regards.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
Antonio Linares
Site Admin
Posts: 42422
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 15 times
Been thanked: 48 times
Contact:

Post by Antonio Linares »

Michel,

Many thanks for your feedback,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 8737
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 2 times
Contact:

Post 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 | Expand

oOutlook:CreateItem(1)


EMG
Post Reply