Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Find Folder, Remove contacts and import contacts from Ex
Message
 
 
To
14/12/2009 18:19:19
Scott Sherman
Puyallup Tribal Health Authority
Tacoma, Washington, United States
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01439064
Message ID:
01439126
Views:
59
Why are you using ON ERROR when it's much simpler and convenient to wrap a line of code that could error out in TRY...ENTRY?
You can check for a folder existence by looping through the folders collection.
In order to delete all items in a collection, you have to use a regular FOR loop and start from the end.
lcFolderName = "text weather"
llFolderExists = .F.
FOR EACH loFolder IN myFolder.Folders
	IF loFolder.Name =  lcFolderName
		llFolderExists = .T.
		lcTWfolder = loFolder
		EXIT
	ENDIF	
ENDFOR

IF NOT llFolderExists 
	lcTWfolder = myFolder.Folders.ADD("text weather")
	? "Creating folder"
ENDIF	

fldContacts = lcTWfolder.Items
myItems = fldContacts.RESTRICT("[CompanyName] = 'Texting'")
FOR i=myItems.Count TO 1 STEP -1
	myItem = myItems.Item(i)
	IF (myItem.CLASS = 40)
		myItem.Delete()
	ENDIF
ENDFOR
>I have the import of contacts from Excel working great but I would like to be able to find a contact folder named 'text weather' and create it if it does not exist. myNewFolder = myFolder.Folders.ADD("text weather") creates the folder but errors if it is not there. On the other hand, fldContacts = myFolder.Folders("text weather").Items opens the correct folder by errors if it does not exist.
>
>I also need to remove all contacts that have companyname = 'Texting'. I made a stab at it below but it only deletes some of the contacts that I want to remove.
>m.excelcopy = "TextImport.xls"
>open_excel_load_outlook(m.excelcopy)
>
>FUNCTION open_excel_load_outlook
>	PARAMETERS m.excelFileName
>	SET SAFETY OFF
>	IF NOT FILE(m.excelFileName)
>		WAIT WINDOW (m.excelFileName + " was not found.")
>		RETURN .F.
>	ENDIF
>
>	myOlApp = CREATEOBJECT("Outlook.Application")
>	nms = myOlApp.GetNamespace("MAPI")
>	myFolder = nms.GetDefaultFolder(10)
>	ON ERROR DO exit_program
>&& myNewFolder = myFolder.Folders.ADD("text weather")
>	fldContacts = myFolder.Folders("text weather").Items
>	myItems = fldContacts.RESTRICT("[CompanyName] = 'Texting'")
>	FOR EACH myItem IN myItems
>		IF (myItem.CLASS = 40)
>&& MESSAGEBOX(myItem.FULLNAME + ": " + TTOC(myItem.LastModificationTime) + ": " + myItem.CompanyName)
>			myItems.REMOVE (1)
>		ENDIF
>	NEXT
>	xlApp = CREATEOBJECT("Excel.Application")
>	wkb = xlApp.Workbooks.OPEN(m.excelFileName)
>	WKS = wkb.Sheets(1)
>	WKS.ACTIVATE
>*!*		xlApp.VISIBLE = .T.
>&& xlApp.Workbooks(1).Worksheets(1).ACTIVATE
>	xlApp.RANGE("A2").SELECT
>
>	lngRows = WKS.UsedRange.ROWS.COUNT
>	DO WHILE LEN(xlApp.activecell.offset(0,3).VALUE) > 0
>&& Debug.Print "On Row " & lngCurrentRow
>		strName = xlApp.activecell.offset(0,5).VALUE
>		strEMail = xlApp.activecell.offset(0,4).VALUE
>		IF LEN(xlApp.activecell.offset(0,5).VALUE ) > 0 THEN
>&& MESSAGEBOX("Name : " + xlApp.activecell.offset(0,5).VALUE )
>			con = fldContacts.ADD(2)
>			con.FULLNAME = xlApp.activecell.offset(0,5).VALUE
>			con.FileAs = xlApp.activecell.offset(0,5).VALUE
>*!*	         con.Email1Address = xlApp.activecell.offset(0,4).value
>			con.FirstName = xlApp.activecell.offset(0,0).VALUE
>			con.LastName = xlApp.activecell.offset(0,1).VALUE
>			con.CompanyName = xlApp.activecell.offset(0,2).VALUE
>			con.MobileTelephoneNumber = xlApp.activecell.offset(0,3).VALUE
>			con.CLOSE (0)
>		ENDIF
>		xlApp.activecell.offset(1,0).SELECT
>	ENDDO
>	wkb.CLOSE
>	xlApp.QUIT
>	xlApp = NULL
>&& myOlApp.Quit
>	myOlApp = NULL
>ENDFUNC
>
>PROCEDURE exit_program
>	MESSAGEBOX("Make sure Contacts has folder named 'text weather'",16,"Program Error")
>	myOlApp = NULL
>
>	CLEAR READ ALL				&& Doesn't clear foundation read.
>
>	CLOSE DATABASES
>	CLEAR MEMORY
>	CLEAR PROGRAM
>*		CLEAR ALL					&& Closes all data bases & releases memory.
>	CLEAR						&& Clean up screen.
>
>	CANCEL						&& Clear foundation read.
>
>ENDPROC
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform