FoxPro Programming
Problem with Outlook?
Gravatar is a globally recognized avatar based on your email address. Problem with Outlook?
  Denis Chassé
  All
  Apr 30, 2024 @ 08:05am

Hello all,

I execute this code. First time I execute everything's fine. Second time my application hangs and I have to reboot my computer. I guess that there could be something related to outlook still in memory. But I don't understand.

lContinue = .F.

oOutlook = CREATEOBJECT("Outlook.Application")
outlookAccounts = oOutlook.GetNamespace("MAPI").Accounts
FOR i = 1 TO outlookAccounts.Count
    IF outlookAccounts.Item(i).DisplayName = "myemail@mycompany.com" THEN
		lContinue = .T.
        EXIT
    ENDIF
ENDFOR
oOutlook = null 
outlookAccounts = null

IF !lContinue
	Messagebox( "You can't use that application.")
	QUIT
ENDIF 

Gravatar is a globally recognized avatar based on your email address. re: Problem with Outlook?
  Tore Bleken
  Denis Chassé
  Apr 30, 2024 @ 09:45am

You must release the variables in reverse order. It's also recommended to use Release to absolutely make sure that the variables are released. IOW

outlookAccounts = null
oOutlook = null
Release outlookAccounts && Recommended
Release outlook && Recommended  

Gravatar is a globally recognized avatar based on your email address. re: Problem with Outlook?
  Denis Chassé
  Tore Bleken
  May 1, 2024 @ 03:48am

Hi Tore,

Thank you for replying. I have the same problem. Here is the revised code.

lcontinue = .F.
oOutlook = CREATEOBJECT("Outlook.Application")
IF VARTYPE( oOutlook) = "U"
	Messagebox( "Outlook must be running")
	oOutlook = null
	RELEASE oOutlook	
	QUIT 
ELSE 
	outlookAccounts = oOutlook.GetNamespace("MAPI").Accounts
	FOR i = 1 TO outlookAccounts.Count
	    IF outlookAccounts.Item(i).DisplayName = "SomeEmail@mybusiness.com" THEN
			lcontinue = .T.
	        EXIT
	    ENDIF
	ENDFOR
	outlookAccounts = null
	RELEASE outlookAccounts

	IF !lcontinue
		Messagebox( "You can't use the application.")
		oOutlook = null
		RELEASE oOutlook	
		quit
	ENDIF 
ENDIF 
oOutlook = null
RELEASE oOutlook	

Gravatar is a globally recognized avatar based on your email address. re: Problem with Outlook?
  Tore Bleken
  Denis Chassé
  May 1, 2024 @ 04:54am

Are you showing all the code?, I mean, there's nothing else in between the lines you show?

Added later:
Have you tried GetObject instead pf CreateObject?
Another possibility is that VFP may need some time to release the object(s)?

Gravatar is a globally recognized avatar based on your email address. re: Problem with Outlook?
  Denis Chassé
  Tore Bleken
  May 1, 2024 @ 10:01am

Yes all the code

Here is the revised code.

lContinuer = .F.
oOutlook = CREATEOBJECT("Outlook.Application")
IF VARTYPE( oOutlook) = "U"
	DO FORM ts_Messagebox WITH I("Outlook must be running")
	oOutlook = null
	RELEASE oOutlook	
	QUIT 
ELSE 
	oMapi = oOutlook.GetNamespace("MAPI")
	outlookAccounts = oMapi.Accounts
	FOR i = 1 TO outlookAccounts.Count
	    IF outlookAccounts.Item(i).DisplayName = "anemail@mycompany.com" THEN
			lContinuer = .T.
	        EXIT
	    ENDIF
	ENDFOR
	outlookAccounts = null
	RELEASE outlookAccounts
	oMAPI = null
	RELEASE oMAPI

	IF !lContinuer
		DO FORM ts_Messagebox WITH I("You can't use the application.")
		oOutlook = null
		RELEASE oOutlook	
		quit
	ENDIF 
ENDIF 
oOutlook = null
RELEASE oOutlook	

Even after the adjustments I have the same problem. Couple of things to mention though. If I run my code through the debugger First execution runs ok. but after that I have to reboot my computer. If I run through compiled app the message "You can't use the application." is not even shown. and after the non-message I have to reboot my computer if I want to run that code again.

Gravatar is a globally recognized avatar based on your email address. re: Problem with Outlook?
  Tore Bleken
  Denis Chassé
  May 1, 2024 @ 10:03am

Please read my previous, updated message.

Gravatar is a globally recognized avatar based on your email address. re: Problem with Outlook?
  Denis Chassé
  Denis Chassé
  May 1, 2024 @ 10:08am

Oops I haven't tried with GetObjects. I'll get back to you

Gravatar is a globally recognized avatar based on your email address. re: Problem with Outlook?
  Denis Chassé
  Denis Chassé
  May 1, 2024 @ 10:22am

I never used getobject.

I tried this and it gave me an error

oOutlook = getobject( ,"Outlook.Application")

What's wrong?

Gravatar is a globally recognized avatar based on your email address. re: Problem with Outlook?
  Tore Bleken
  Denis Chassé
  May 1, 2024 @ 07:16pm

You have asked the same question in at least two forums, let's continue in Level Extreme.

Gravatar is a globally recognized avatar based on your email address. re: Problem with Outlook?
  Denis Chassé
  Tore Bleken
  May 2, 2024 @ 12:55am

I posted on two places. Here and Level Extreme. I agree to continue there.

© 1996-2024