Results 1 to 13 of 13
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Houston, Texas, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add a name in the TO: address with code (MS Office 2003)

    I have a MS Outook form that will request the name of the Dept. manager in the field (Reqby). I want to be able to add this name to the TO: line that already has a name in it.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Add a name in the TO: address with code (MS Of

    Take a look at the Recipients collection for the MailItem: the .Add method lets you add names/addresses to any field, if I recall correctly.

    Or is that not working?? You definitely should get a security alert...

  3. #3
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Houston, Texas, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add a name in the TO: address with code (MS Of

    Not sure that is what I am looking for. In my form (see attached), we add the name of the Dept. manager that is hiring a new person. I want to add that name to the distribution (TO on who gets a copy of the form.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Add a name in the TO: address with code (MS Of

    See the attached sample of what I was referring to. You'll need to use your own field names, obviously.

  5. #5
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Houston, Texas, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add a name in the TO: address with code (MS Of

    I got it to add the name up top but now I get a different error. Use the Global Address List as our default. and I wonder if this is the problem.
    I have name already in the TO address and it adds the new name after it. I get this error now.
    "The following recipients9s) count not be reached"
    Daniel Reyes on 4/4/2005 2:32 PM -=-=-=- Error is [0x80070057-000000000=00000000]

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Add a name in the TO: address with code (MS Of

    That error doesn't look familiar, and doesn't even make any grammatical sense. I'm not sure what to suggest. If you press Ctrl+K before sending, does the address resolve? If so, I think you could add that step to your script and see if that helps. If not, then a different technique might be required to populate the To field.

  7. #7
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Houston, Texas, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add a name in the TO: address with code (MS Of

    It doesn't give me a chang to try the Ctril K. how would I add that in code?
    There is somthing I am not sure about. Is the Recipient the same as the Global Address List? If my Address List book in MS outlook is not set to GAL but to Contact or Recipients my forms don't work. Wonder if there is something connected with that.

  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Add a name in the TO: address with code (MS Of

    I can't help you with all your questions, but the code equivalent to Ctrl-K is

    Recipients.Resolve

    and you will need an error handler for unresolved recipients. And, no, recipients are not the same as the GAL, a recipient is one of the collection of Recipients in an Outlook Item, whereas the GAL is an AddressList in the AddressLists Collection.

    I think you'll have to have the GAL mapped as an address book for code to work for any user if the recipients are likely to be in the GAL, and it isn't known if they are in those user contacts in Folders permitted and mapped as an Outlook Address Book. I think (?) you can select the GAL using

    Outlook.NameSpace.AddressLists("Global Address List")

    but I haven't tested it. Afterthought, there might be CDO mehods available to get at the GAL.
    -John ... I float in liquid gardens
    UTC -7ąDS

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Add a name in the TO: address with code (MS Of

    Name resolution in a custom form should work exactly the same way as name resolution in a default form. Address books will be searched for your entered name/address in the order the user specified in the Address Book dialog's Addressing sub-dialog (Tools>Options...).

    The Recipients collection is for that item/message/form only. Do not try to link the recipients collection to the address book. Just pretend that anything you add to the recipients collection is identical to anything you typed into the To box manually and trust Outlook to behave the same way. For better or worse. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  10. #10
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Houston, Texas, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add a name in the TO: address with code (MS Of

    I just ran the form and in picture 1 - I shows my name in the TO as the default and the second name Juan V. that is added from the Mnagers name field (deptname).
    I use the following to copy the name to TO:

    '-=-=-=-=-=-=-=-
    Sub Update2()
    Dim recip
    Set recip = Item.Recipients.Add (Item.userproperties.Find("Deptman").Value)
    recip.type = olTo'
    End Sub
    '-=-=-=-=-=-=-

  11. #11
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Houston, Texas, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add a name in the TO: address with code (MS Of

    When I "Send" the form i get the following error:

  12. #12
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Add a name in the TO: address with code (MS Of

    It seems the problem is with your name as it was stored in the form, not the one being added in code. If you delete your name from your form and add it using similar code as the code being used for the manager, does that resolve the error??

  13. #13
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Houston, Texas, USA
    Posts
    432
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add a name in the TO: address with code (MS Of

    Got it working now. OK, I cheated. I deleted the Deptman field and moved the TO address in its place.

    It works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •