Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    deiniolj is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Location
    Wales
    Posts
    40

    SendMail

    What I am trying to do is use SendMail to work with a Combo box. So when the box is changed to say Ordered it sends a mail out to joebloggs@bah.com, But I also need to be able to specifiy the From Field. Being having a play and at the moment it picks up my personel account out Outlook.

    i.e me@outlook.com where I need it to be say company@outlook.com

    Any idea's

    Don't mind if it will have to be in VB, Just t let you know



    Combo box will have around 10 item in the drop down but will only sent email from 4 of the choices. i.e Start, Middle, Ordered, Finish

  2. #2
    deiniolj is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Location
    Wales
    Posts
    40
    Sorry for my rubbish grammar, being playing with access all night and my head hurts..

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    If you're using automation to send the email, you can do this:

    MyMail.SentOnBehalfOfName = "company@outlook.com"

    Not sure if you're using SendObject.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    deiniolj is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Wales
    Posts
    40
    No send object, only From, To, CC, Subject, Body.

    Sorry to be a pain what would be the best way to structre this this in VB, I'm guessing I would run it from the after update command of the combo box in question.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Here are the basics on automation:

    http://support.microsoft.com/?kbid=161088

    Using that code, this should work:

    objOutlookMsg.SentOnBehalfOfName = "company@outlook.com"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    deiniolj is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Wales
    Posts
    40
    Where in the automation script would I put this, and how would I get it to run if the combo box was moved to let say ordered.

  7. #7
    deiniolj is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Wales
    Posts
    40
    Also what happens if other people are using Thunderbird..

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Don't know how to automate with clients other than Outlook. SendObject will work with the user's default mail client, but I don't know how to specify the sender with SendObject (you don't need to be sending an object to use it).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    deiniolj is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Wales
    Posts
    40
    I used this code that seems to work, but I don't now where to add your bit. and how
    Private Sub Command403_Click()
    '******begin code******
    Dim Email As String
    Dim ref As String
    Dim origin As String
    Dim destination As String
    Dim Notes As String

    '**create variables for Outlook
    Dim objOutlook As Outlook.Application
    Dim objEmail As Outlook.MailItem

    '**gathers information from your form. this sets the string variable to your fields
    Email = Me.Email
    CC = "test@home.com"
    ref = "Item Ordered Test"
    origin = "Test Test"
    destination = Me.Email
    Notes = "This is just a Drill"

    '***creates an instance of Outlook
    Set objOutlook = CreateObject("Outlook.application")
    Set objEmail = objOutlook.CreateItem(olMailItem)

    '***creates and sends email
    With objEmail
    .To = Email
    .CC = CC
    .Subject = ref & " " & origin & " to " & destination
    .Body = Notes
    .Send
    'modify or see what you have created before sending the email
    End With

    '**closes outlook
    objOutlook.Quit
    Set objEmail = Nothing

    Exit Sub
    '****end code****
    End Sub

  10. #10
    deiniolj is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Wales
    Posts
    40
    Also how would I link this to the combo box..

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    .SentOnBehalfOfName = "company@outlook.com"

    right after the CC (pretty much anywhere after the With and before the .Send). As to the code, try a Select/Case or If/Then/Else block that tests the value of the combo, and executes your code if the value is one of the ones you want to send an email on.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    deiniolj is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Wales
    Posts
    40
    Help

    I need this code to work based on another field. it will be based on 2 things Ordered and sent. So when I click the save button it send the email depending what currently in that combo box..

    this code work fine on it own, need to make a few tweeks to the body and subject. But how would I get it working other wise.

    Private Sub Command403_Click()
    '******begin code******
    Dim Email As String
    Dim ref As String
    Dim origin As String
    Dim destination As String
    Dim Notes As String

    '**create variables for Outlook
    Dim objOutlook As Outlook.Application
    Dim objEmail As Outlook.MailItem

    '**gathers information from your form. this sets the string variable to your fields
    Email = Me.Email
    CC = "test@home.com"
    ref = "Item Ordered Test"
    origin = "Test Test"
    destination = Me.Email
    Notes = "This is just a Drill"

    '***creates an instance of Outlook
    Set objOutlook = CreateObject("Outlook.application")
    Set objEmail = objOutlook.CreateItem(olMailItem)

    '***creates and sends email
    With objEmail
    .To = Email
    .CC = CC
    .Subject = ref & " " & origin & " to " & destination
    .Body = Notes
    .Send
    'modify or see what you have created before sending the email
    End With

    '**closes outlook
    objOutlook.Quit
    Set objEmail = Nothing

    Exit Sub
    '****end code****
    End Sub

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'm confused as to what the question is:

    Quote Originally Posted by deiniolj View Post
    this code work fine on it own, need to make a few tweeks to the body and subject. But how would I get it working other wise.
    Does it work, or not?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    deiniolj is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Wales
    Posts
    40
    Basically what I want is if the combo box says Order. Then I press the save button it sends an email with a body and subject with lettering based on order. If the combo box says Sent it send an email with lettering based on sent. Does that make better sense. I'm guessing it will go in the after update command of the save button.
    (Yes the sendmail script above does work on it own. if I press the current button it assigned to in a test form it send an email to whoever it says in the email box.) Basically i need to send multiple emails based on a combo selection.

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It sounds like you want to use either an If/Then/Else block or Select/Case to test the value of the combo, and set certain values depending on the selection.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Changing the way my Sendmail function sends e-mails
    By slaterino in forum Programming
    Replies: 1
    Last Post: 04-29-2009, 12:40 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