Results 1 to 3 of 3
  1. #1
    jonny is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    17

    Number (ContactID) instead the e-mail of contact

    I have some form with combobox, where I'm selecting a contact whom to send an e-mail. This combo that called 'Delivered_By' is retrieving data from table 'Contacts'.



    Row source of this field is: SELECT Contacts.[Contact ID], Contacts.[Contact Name] FROM Contacts ORDER BY Contacts.[Contact Name];

    Code:
    With objOutlookMsg
                  ' Add the To recipient(s) to the message.
                  Set objOutlookRecip = .Recipients.Add(Delivered_By)
                  objOutlookRecip.Type = olTo
    When the message is opening in 'To' field appears a NUMBER (ContactID) instead the e-mail of contact. Any advices?

    Thank you

  2. #2
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    For a start how does it know what the email address is? your combo box row source should be

    SELECT [Contact ID], [Contact Name], [Email Address] FROM Contacts WHERE [Email Address] Is Not Null ORDER BY [Contact Name];

    You bound column in your combo should be set to 1 (Contact id)

    Then you need to revise this line of code
    Code:
     
     
    Set objOutlookRecip = .Recipients.Add(Delivered_By)
    to

    Code:
     
    Set objOutlookRecip = .Recipients.Add(Me.Delivered_By.Column(2))
    Because the columns are zero based in the combo box column(2) is the third column in the combo. I have also included an Is Not Null condition as you can only send a person an email if they have an email address to send it to.

    Also I have Assumed the [Email Address] is the actual name of the field in your contacts table. If different you will need to change it.

    David

  3. #3
    jonny is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2009
    Posts
    17
    Hi Sir, thank you for your help.
    I solved a problem with following code:
    Code:
    Private Sub btnSend_Click()
        Dim oOApp As Outlook.Application
        Dim oOMail As Outlook.MailItem
    
        Set oOApp = CreateObject("Outlook.Application")
        Set oOMail = oOApp.CreateItem(olMailItem)
        
        With oOMail
            .To = Me.Received_By.Column(1) & " <" & Me.Received_By.Column(2) & ">"
            .Subject = "email subject"
            .Body = "email message"
            .Display
        End With
    End Sub
    Regards..

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

Similar Threads

  1. last contact
    By mitchy1111 in forum Queries
    Replies: 3
    Last Post: 10-10-2009, 04:53 PM
  2. email contact button
    By nwalke in forum Programming
    Replies: 3
    Last Post: 07-02-2009, 07:11 AM
  3. E-mail Reports
    By Mike Cooper in forum Reports
    Replies: 2
    Last Post: 08-04-2008, 12:58 AM
  4. Mail merge
    By grgerhard in forum Forms
    Replies: 0
    Last Post: 04-25-2006, 05:06 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