Results 1 to 4 of 4
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191

    retrieve email address from OL

    Hi Guy's this one is a bit of a long shot, i am probably miles away trying this,



    Is there a way i can retrieve outlook email addresses, then further more if there are 7 contacts in outlook contacts for a specific company and add a criteria such as:

    Joe Bloggs joe@companyname.com
    Fred Bloggs fred@companyname.com

    Dim PartName as string

    PartName = "company" so i can view contacts in a msgbox that is any email address from companyname.com

    This is what i have so far but i am probably incorrect!

    Code:
     Dim myOutlook As Outlook.Application
       Dim myItems As ContactItem
        Dim msgBody As String
        Dim i As Integer
        
       Set myOutlook = CreateObject("Outlook.Application")
       Set myItems = myOutlook.CreateItem(olContactItem)
       With myItems
       For i = 1 To myItems.Email1Address
       msgBody = msgBody & myItems.Email1Address
       Next i
       MsgBox (msgBody)
        
        End With

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Totally not tested but you might want to "validate" the email using the InStr function:

    Code:
    Dim myOutlook As Outlook.Application
       Dim myItems As ContactItem
        Dim msgBody As String
        Dim i As Integer 
       dim sCompany as string
    'set your variable from your form or recordset
    sCompany=Me.Company
        
       Set myOutlook = CreateObject("Outlook.Application")
       Set myItems = myOutlook.CreateItem(olContactItem)
       With myItems
       For i = 1 To myItems.Email1Address
          If InStr(myItems.EmailAddress,sCompany)>0 then msgBody = msgBody & myItems.Email1Address
       Next i
       MsgBox (msgBody)
        
        End With
    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,191
    Hi Vlad, thank you, although you said not tried, i am unsure if this is the wrong method of retrieving email addresses from OL, it comes up with a debug run time error 13 type mismatch, I have used a customer name that is in OL contacts to replace sCompany but removed from the code and replaced with bloggs so that customer name isn't revelaed

    Code:
    Dim myOutlook As Outlook.Application
       Dim myItems As ContactItem
        Dim msgBody As String
        Dim i As Integer
       Dim sCompany As String
    'set your variable from your form or recordset
    sCompany = "bloggs"
        
       Set myOutlook = CreateObject("Outlook.Application")
       Set myItems = myOutlook.CreateItem(olContactItem)
       With myItems
       For i = 1 To myItems.Email1Address "debug"
          If InStr(myItems.EmailAddress, sCompany) > 0 Then msgBody = msgBody & myItems.Email1Address
       Next i
       MsgBox (msgBody)
        
        End With
        

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 05-04-2017, 08:06 AM
  2. Replies: 1
    Last Post: 11-07-2016, 11:18 AM
  3. Email report to value (email address) in a field
    By JackieEVSC in forum Programming
    Replies: 7
    Last Post: 08-28-2015, 11:18 AM
  4. Replies: 1
    Last Post: 05-01-2014, 11:37 AM
  5. Replies: 1
    Last Post: 07-16-2013, 12:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums