Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / November 2006

Tip: Looking for answers? Try searching our database.

itm in itms folder question.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carol G - 29 Nov 2006 21:23 GMT
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
...
Sue Mosher [MVP-Outlook] - 29 Nov 2006 21:33 GMT
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

Signature

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
 

>I am wishing to capture the itm from the collection when it is found and
> then overwrite the info using with itm.
[quoted text clipped - 28 lines]
>         .User4 = strCompName2
> ...
Carol G - 30 Nov 2006 16:41 GMT
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

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

Signature

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

>I am wishing to capture the itm from the collection when it is found and
> then overwrite the info using with itm.
[quoted text clipped - 28 lines]
>         .User4 = strCompName2
> ...
Sue Mosher [MVP-Outlook] - 30 Nov 2006 18:40 GMT
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?
Signature

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
 

> Sorry, Actually I had some code before this that checked that it is there to
> find.
[quoted text clipped - 12 lines]
>    'create it
> End If

>>I am wishing to capture the itm from the collection when it is found and
>> then overwrite the info using with itm.
[quoted text clipped - 28 lines]
>>         .User4 = strCompName2
>> ...
Carol G - 30 Nov 2006 20:17 GMT
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
Sue Mosher [MVP-Outlook] - 30 Nov 2006 20:51 GMT
These two statements are in the wrong order:

   With itm

End If   'strDecision = "0"
Signature

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
 

> OK here goes,
>
[quoted text clipped - 184 lines]
>
> End Sub
Carol G - 30 Nov 2006 21:40 GMT
Thanks
I haven't time to try it out until later.
Carol PS thanks for not laughing

These two statements are in the wrong order:

   With itm

End If   'strDecision = "0"
Signature

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

> OK here goes,
>
[quoted text clipped - 184 lines]
>
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.