![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
I am wishing to capture the itm from the collection when it is found and
then overwrite the info using with itm. If it is not found then I wish to set a new itm and add the info. As the code to add or overwrite is the same I was hoping to just have it written once. I think it won't work this way because once I'm out of the for loop my itm is gone. I am very unsure of all this. Thanks for any suggestions. Carol If strDecision = "0" Then For Each itm In itms If strNameList = itm.FullName Then Debug.Print itm.FullName & " is found" End If 'strNameList = itm.FullName Exit For Next with itm **** Here is the problem*** Else ' if decision is new Set itm = itms.Add end if 'Then code for add ing record. 'Standard Contact fields .CustomerID = strCustomerID .FirstName = strFName1 .LastName = strLName1 .CompanyName = strCompName1 .User4 = strCompName2 .... |
#2
|
|||
|
|||
![]()
You are missing any code to test whether itm really was found:
If Not itm Is Nothing Then ' update it Else 'create it End If -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Carol G" wrote in message news:aTmbh.386356$1T2.195613@pd7urf2no... I am wishing to capture the itm from the collection when it is found and then overwrite the info using with itm. If it is not found then I wish to set a new itm and add the info. As the code to add or overwrite is the same I was hoping to just have it written once. I think it won't work this way because once I'm out of the for loop my itm is gone. I am very unsure of all this. Thanks for any suggestions. Carol If strDecision = "0" Then For Each itm In itms If strNameList = itm.FullName Then Debug.Print itm.FullName & " is found" End If 'strNameList = itm.FullName Exit For Next with itm **** Here is the problem*** Else ' if decision is new Set itm = itms.Add end if 'Then code for add ing record. 'Standard Contact fields .CustomerID = strCustomerID .FirstName = strFName1 .LastName = strLName1 .CompanyName = strCompName1 .User4 = strCompName2 ... |
#3
|
|||
|
|||
![]()
Sorry, Actually I had some code before this that checked that it is there to
find. My problem is that if I place the With itm inside the for loop. When the loop closes do I lose my itm.FullName which I wish to use out of the loop with "With itm"? Hope that my question is making sense. I just recently bought your book and am finding it helpful but I have a long way to go. Thanks "Sue Mosher [MVP-Outlook]" wrote in message ... You are missing any code to test whether itm really was found: If Not itm Is Nothing Then ' update it Else 'create it End If -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Carol G" wrote in message news:aTmbh.386356$1T2.195613@pd7urf2no... I am wishing to capture the itm from the collection when it is found and then overwrite the info using with itm. If it is not found then I wish to set a new itm and add the info. As the code to add or overwrite is the same I was hoping to just have it written once. I think it won't work this way because once I'm out of the for loop my itm is gone. I am very unsure of all this. Thanks for any suggestions. Carol If strDecision = "0" Then For Each itm In itms If strNameList = itm.FullName Then Debug.Print itm.FullName & " is found" End If 'strNameList = itm.FullName Exit For Next with itm **** Here is the problem*** Else ' if decision is new Set itm = itms.Add end if 'Then code for add ing record. 'Standard Contact fields .CustomerID = strCustomerID .FirstName = strFName1 .LastName = strLName1 .CompanyName = strCompName1 .User4 = strCompName2 ... |
#4
|
|||
|
|||
![]()
Sorry, but it doesn't make sense. The itm object should be usable outside the loop. You do have a Dim itm statement in your procedure, right?
-- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Carol G" wrote in message news:eRDbh.401502$R63.190908@pd7urf1no... Sorry, Actually I had some code before this that checked that it is there to find. My problem is that if I place the With itm inside the for loop. When the loop closes do I lose my itm.FullName which I wish to use out of the loop with "With itm"? Hope that my question is making sense. I just recently bought your book and am finding it helpful but I have a long way to go. Thanks "Sue Mosher [MVP-Outlook]" wrote in message ... You are missing any code to test whether itm really was found: If Not itm Is Nothing Then ' update it Else 'create it End If "Carol G" wrote in message news:aTmbh.386356$1T2.195613@pd7urf2no... I am wishing to capture the itm from the collection when it is found and then overwrite the info using with itm. If it is not found then I wish to set a new itm and add the info. As the code to add or overwrite is the same I was hoping to just have it written once. I think it won't work this way because once I'm out of the for loop my itm is gone. I am very unsure of all this. Thanks for any suggestions. Carol If strDecision = "0" Then For Each itm In itms If strNameList = itm.FullName Then Debug.Print itm.FullName & " is found" End If 'strNameList = itm.FullName Exit For Next with itm **** Here is the problem*** Else ' if decision is new Set itm = itms.Add end if 'Then code for add ing record. 'Standard Contact fields .CustomerID = strCustomerID .FirstName = strFName1 .LastName = strLName1 .CompanyName = strCompName1 .User4 = strCompName2 ... |
#5
|
|||
|
|||
![]()
OK here goes,
Here's my code ,don't laugh. This is done in Access to transfer to OUtlook. My problem is that I thought once the for loop closed that the itm.FullName that I matched would close also.Down where the With itm code is placed is where I'm having Trouble. I originally had the with itms code inside the If strDecision = "0" Then ' User wishes to to Overwrite an itm. loop. I then got an if without else error message. When I moved it out of the loop the message went away but I don't think the code works the way I have it. Thanks Again Carol Private Sub cmdOutlookExport_Click() 'Declare the pfld variable as Public so it can be set in one procedure 'and used in another Dim fld As Outlook.MAPIFolder Dim appOutlook As Outlook.Application Dim nms As Outlook.NameSpace Dim itms As Outlook.Items Dim itm As Outlook.ContactItem Set appOutlook = CreateObject("Outlook.Application") Set nms = appOutlook.GetNamespace("MAPI") Set fld = nms.GetDefaultFolder(olFolderContacts) 'Set what kind of folder Set itms = fld.Items 'Outlook folder item On Error GoTo ErrorHandler Dim strCustomerID As String Dim strFName1 As String Dim All the rest of the variables that I wish to transfer to. strCustomerID = Parent!txtCustomerID strFName1 = FirstName_Concatenate_For_Outlook() assign all the other variables here 'Check Outlook for duplicates For Each itm In itms If strLName1 = itm.LastName Then strNameList = strNameList & ";" & itm.FullName End If Next If strNameList = "" Then MsgBox "Looped through list" & strNameList & " is strNameList" End If If strNameList "" Then DoCmd.OpenForm "frmDuplicateValue", OpenArgs:=strNameList, WindowMode:=acDialog 'Stop here and wait until form goes away 'MsgBox "This should only be triggered if duplicate value found" If Not IsLoaded("frmDuplicateValue") Then MsgBox "Update has been canceled." Exit Sub End If 'Not Is Loaded strDecision = Forms("frmDuplicateValue").Tag DoCmd.Close acForm, "frmDuplicateValue" End If 'strNameList"" 'Separate the option from the FullName strNameList = Mid(strDecision, 2) strDecision = Replace(strDecision, Mid(strDecision, 2), "") If strDecision "N" And strDecision "0" Then This means that the user wishes to update the information rather than make new or overwrite. For Each itm In itms 'Debug.Print itm.FullName If strNameList = itm.FullName Then Debug.Print itm.FullName & " is found" With itm If Len(.CustomerID) = 0 Then .CustomerID = strCustomerID If Len(.FirstName) = 0 Then .FirstName = strFName1 All the other fields to update here. .Save End With MsgBox "Contact Updated Successfully" Exit Sub End If 'strNameList = itm.FullName Next End If 'strDecision "N" And strDecision "0" If strDecision = "0" Then ' User wishes to to Overwrite an itm. For Each itm In itms If strNameList = itm.FullName Then End If 'strNameList = itm.FullName Exit For Next With itm ' This is where I want to use either this with itm to overwrite or the one following to add. Else ' if decision is new Set itm = itms.Add With itm End If 'strDecision = "0" 'Write values from variables to fields in the new Contact item 'Standard Contact fields .CustomerID = strCustomerID .FirstName = strFName1 All the other fields to deal with .Close (olSave) End With MsgBox " Contact exported! from Form" ErrorHandlerExit: Exit Sub ErrorHandler: MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description Resume ErrorHandlerExit End Sub |
#6
|
|||
|
|||
![]()
These two statements are in the wrong order:
With itm End If 'strDecision = "0" -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Carol G" wrote in message news:4%Gbh.402851$R63.193523@pd7urf1no... OK here goes, Here's my code ,don't laugh. This is done in Access to transfer to OUtlook. My problem is that I thought once the for loop closed that the itm.FullName that I matched would close also.Down where the With itm code is placed is where I'm having Trouble. I originally had the with itms code inside the If strDecision = "0" Then ' User wishes to to Overwrite an itm. loop. I then got an if without else error message. When I moved it out of the loop the message went away but I don't think the code works the way I have it. Thanks Again Carol Private Sub cmdOutlookExport_Click() 'Declare the pfld variable as Public so it can be set in one procedure 'and used in another Dim fld As Outlook.MAPIFolder Dim appOutlook As Outlook.Application Dim nms As Outlook.NameSpace Dim itms As Outlook.Items Dim itm As Outlook.ContactItem Set appOutlook = CreateObject("Outlook.Application") Set nms = appOutlook.GetNamespace("MAPI") Set fld = nms.GetDefaultFolder(olFolderContacts) 'Set what kind of folder Set itms = fld.Items 'Outlook folder item On Error GoTo ErrorHandler Dim strCustomerID As String Dim strFName1 As String Dim All the rest of the variables that I wish to transfer to. strCustomerID = Parent!txtCustomerID strFName1 = FirstName_Concatenate_For_Outlook() assign all the other variables here 'Check Outlook for duplicates For Each itm In itms If strLName1 = itm.LastName Then strNameList = strNameList & ";" & itm.FullName End If Next If strNameList = "" Then MsgBox "Looped through list" & strNameList & " is strNameList" End If If strNameList "" Then DoCmd.OpenForm "frmDuplicateValue", OpenArgs:=strNameList, WindowMode:=acDialog 'Stop here and wait until form goes away 'MsgBox "This should only be triggered if duplicate value found" If Not IsLoaded("frmDuplicateValue") Then MsgBox "Update has been canceled." Exit Sub End If 'Not Is Loaded strDecision = Forms("frmDuplicateValue").Tag DoCmd.Close acForm, "frmDuplicateValue" End If 'strNameList"" 'Separate the option from the FullName strNameList = Mid(strDecision, 2) strDecision = Replace(strDecision, Mid(strDecision, 2), "") If strDecision "N" And strDecision "0" Then This means that the user wishes to update the information rather than make new or overwrite. For Each itm In itms 'Debug.Print itm.FullName If strNameList = itm.FullName Then Debug.Print itm.FullName & " is found" With itm If Len(.CustomerID) = 0 Then .CustomerID = strCustomerID If Len(.FirstName) = 0 Then .FirstName = strFName1 All the other fields to update here. .Save End With MsgBox "Contact Updated Successfully" Exit Sub End If 'strNameList = itm.FullName Next End If 'strDecision "N" And strDecision "0" If strDecision = "0" Then ' User wishes to to Overwrite an itm. For Each itm In itms If strNameList = itm.FullName Then End If 'strNameList = itm.FullName Exit For Next With itm ' This is where I want to use either this with itm to overwrite or the one following to add. Else ' if decision is new Set itm = itms.Add With itm End If 'strDecision = "0" 'Write values from variables to fields in the new Contact item 'Standard Contact fields .CustomerID = strCustomerID .FirstName = strFName1 All the other fields to deal with .Close (olSave) End With MsgBox " Contact exported! from Form" ErrorHandlerExit: Exit Sub ErrorHandler: MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description Resume ErrorHandlerExit End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Newbie question: How to copy an email item from inbox to a folder | Marceepoo | Outlook and VBA | 1 | November 1st 06 06:54 PM |
Deleted Items folder question | 3putt | Outlook Express | 4 | July 4th 06 11:59 AM |
Question about Default Contacts folder | Mervin Williams | Outlook - Using Contacts | 5 | April 13th 06 12:05 AM |
Search Folder Question Please | Bob Newman | Outlook - General Queries | 0 | April 2nd 06 03:34 PM |
.NET AddIn Question UserControl in Folder homepage | David Ing | Outlook and VBA | 8 | March 4th 06 12:24 PM |