Transfer Creating Outlook Error

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Transfer Creating Outlook Error

Post by kpassaur » Wed Nov 01, 2006 8:27 pm

I have modified the script that is show at
http://www.mjtnet.com/usergroup/viewtop ... ok+contact

My Script pulls the contact data from a screen and then runs the script below. It checks to see if an existing contact exists in Outlook and then adds the new contact. it works; however, a few minutes later Outlook cannot be opened. When I look in the Task Manager it is still running. If I close Outlook in the Task Manager and then open it again Outlook runs fine and the new Contact is in it. It is as if Macro Scheduler or my code (I'm sure it is my code) does not stop connecting to Outlook and then it causes it to lock up.

Could someone show me where my error is.

Thanks


[/code]
VBSTART
Function FindContact (strInput)
Dim objOutlook
Dim objNameSpace
Dim objFolder
Dim cItem
Dim strOutput
Dim counter

Const olFolderContacts = 10
Const cTextCaseInsensitive = 1

Set objOutlook = CreateObject("Outlook.application")
Set objNameSpace = objOutlook.GetNameSpace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder(olFolderContacts)
counter = 0
For Each cItem in objFolder.Items
If Instr(1,cItem.FullName,strInput,cTextCaseInsensitive) > 0 Then
counter=counter+1
FindContact = String(45,"~")
' FindContact = String(45,"~") & vbCrLf
FindContact = strOutput & "Full Name:" & vbTab & cItem.FullName & vbCrLf
FindContact = strOutput & strAddress & vbCrLf
FindContact = counter
'Msgbox strOutput, , cItem.Subject
End If
Next

If FindContact = "" Then
'Msgbox "No contacts match search requirements."& vbCrLf & counter, vbInformation,"Contact Search"
End If

' **** Clean up
'
Set objFolder = Nothing
Set objNameSpace = Nothing
set objOutlook = Nothing
END Function
VBEND

VBEval>FindContact("%FullName%"),answer
/MDL>%answer%

CloseDialog>Dialog3
If>%answer%=0
Goto>CreateContact
Endif

If>%answer%=1
MDL>There is already a Contact in Outlook for %FullName% the Program will now Exit
Goto>EOF
Endif

If>%answer%>1
MDL>There is more than one Contact in Outlook for %FullName% the Program will now Exit
Goto>EOF
Endif


Label>CreateContact


VBSTART

Sub AddContact (FullName,EMail,BusinessPhone,HomePhone,MobilePhone,Fax,StreetAddress,City,State,Zip)
Dim objOutlook
Dim itmContact
Dim strMsg

Const olContactItem = 2

Set objOutlook = CreateObject("Outlook.application")
Set itmContact = objOutlook.CreateItem(olContactItem)

itmContact.FullName = FullName
itmContact.EMail1Address = EMail
itmContact.BusinessTelephoneNumber = BusinessPhone
itmContact.HomeTelephoneNumber = HomePhone
itmContact.MobileTelephoneNumber = CellPhone
itmContact.BusinessFaxNumber = Fax
itmContact.HomeAddressStreet = StreetAddress
itmContact.HomeAddressCity = City
itmContact.HomeAddressState = State
itmContact.HomeAddressPostalCode = Zip
'Save and display the Contact
itmContact.Save
itmContact.Display


'Clean up
Set itmContact = Nothing
Set objOutlook = Nothing
End Sub
VBEND

VBRUN>AddContact,%FullName%,%EMail%,%BusinessPhone%,%HomePhone%,%CellPhone%,%Fax%,%StreetAddress%,%City%,%State%,%Zip%

Label>EOF

Code: Select all




User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Nov 01, 2006 9:03 pm

You haven't exited Outlook. Add this before setting the object reference to nothing:

objOutlook.Quit
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

Outlook Quitting

Post by kpassaur » Wed Nov 01, 2006 9:10 pm

Thank you I'll give it a try

kpassaur
Automation Wizard
Posts: 696
Joined: Wed Jul 07, 2004 1:55 pm

After Contact is Added can Outlook remain open

Post by kpassaur » Wed Nov 01, 2006 9:34 pm

First, thank you it now does not lockup Outlook, however, if Outlook is open and you add a contact via the script since the Quit Command ends Outlook the user has to reopen it and search for the Contact that has been added. Is there a different command that would allow Outlook to remain open and just kill the connection MS has made to it. And yes I know this is not a MS issue, but any help would be appriecated.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Nov 01, 2006 9:38 pm

That doesn't make sense to me. Your CreateObject line should CREATE a *NEW* Outlook object and the Quit line should Quit *THAT* instance.

Perhaps Microsoft have done something different with Outlook.

In any case just setting the object to nothing should be sufficient to release a connection to it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts