Button to save entry and then send an email (1 Viewer)

ethan.geerdes

Registered User.
Local time
Today, 15:19
Joined
Jun 4, 2015
Messages
116
I have been googling for a few hours now and found out that I can send an email from access so If I can do that, I want to automate sending a pre-made email to an individual with everything that is on a form. For clarification, I am trying to asssign tasks to people.

For instance

I select some information, everything populates, I choose who I want to assign it to (the person I need to send the email to) and then I want to click a button labeled assign that will input the new record so I can track progress, and then have an email generated and sent to the individual with the information that was in that record.

I found an expression that was like

"If Me.Dirty Then Me.Dirty = False" To save the record.

Any input would be greatly appreciated. Thank you in advance.

Sincerely,
Ethan
 

GinaWhipp

AWF VIP
Local time
Today, 18:19
Joined
Jun 21, 2011
Messages
5,899
Where is the code you found? Or have you not started it yet?
 

ethan.geerdes

Registered User.
Local time
Today, 15:19
Joined
Jun 4, 2015
Messages
116
I have been combing the internet and based on my capabilities because my network that I have the project on, It looks like it is coming down that I have to do it all in the vb editor. I am running vb 6.5 by the way. I think I may have just found something from microsoft. I will upload it once I read through it to see what the great people of this site have to say like yourself. Thank you for the help if you can steer me in the right direction.
 

ethan.geerdes

Registered User.
Local time
Today, 15:19
Joined
Jun 4, 2015
Messages
116
Option Explicit Private Sub Command1_Click() Dim objSession As Object Dim objMessage As Object Dim objRecipient As Object 'Create the Session Object. Set objSession = CreateObject("mapi.session") 'Logon using the session object. 'Specify a valid profile name if you want to. 'Avoid the logon dialog box. objSession.Logon profileName:="MS Exchange Settings" 'Add a new message object to the OutBox. Set objMessage = objSession.Outbox.Messages.Add 'Set the properties of the message object. objMessage.subject = "This is a test." objMessage.Text = "This is the message text." 'Add a recipient object to the objMessage.Recipients collection. Set objRecipient = objMessage.Recipients.Add 'Set the properties of the recipient object. objRecipient.Name = "John Doe" '<---Replace this with a valid 'display name or e-mail alias 'Type can be ActMsgTo, mapiTo, or CdoTo for different CDO versions; 'they all have a constant value of 1. objRecipient.Type = mapiTo objRecipient.Resolve 'Send the message. objMessage.Send showDialog:=False MsgBox "Message sent successfully!" 'Logoff using the session object. objSession.Logoff End Sub
 

GinaWhipp

AWF VIP
Local time
Today, 18:19
Joined
Jun 21, 2011
Messages
5,899
You need to repost with code tags but even before that...

Not sure what you mean by your capabilities... what kind of project did you get assigned that you can't do?
 

GinaWhipp

AWF VIP
Local time
Today, 18:19
Joined
Jun 21, 2011
Messages
5,899
Hmm, after a little more thought...

1. Are your Users using Outlook? If not Outlook then what?
2. What version of Access/Outlook?
 

ethan.geerdes

Registered User.
Local time
Today, 15:19
Joined
Jun 4, 2015
Messages
116
what are the code tags again? I think I have found a different code to use. I will post it as soon as i figure out how to do the code tags. lol
 

ethan.geerdes

Registered User.
Local time
Today, 15:19
Joined
Jun 4, 2015
Messages
116
Code:
Private Sub Command12_Click()
DoCmd.GoToRecord , , acNewRec

  Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
        .Subject = "Test Message"
        .Body = "Body Text"
        .Recipients.to = Me.Combo18.Column(2)
        .Recipients.ResolveAll
        .Display
    End With

End Sub


The code above is what I have listed for my button so far. I already got an error with the Dim olApp As Outlook.Application portion.
 

GinaWhipp

AWF VIP
Local time
Today, 18:19
Joined
Jun 21, 2011
Messages
5,899
Sorry for delay, busy weekend...

Do you have Outlook open when you try to send the eMail?
 

ethan.geerdes

Registered User.
Local time
Today, 15:19
Joined
Jun 4, 2015
Messages
116
no. outlook is not open. I'm assuming I will need to open it though to be able to send the email.
 

GinaWhipp

AWF VIP
Local time
Today, 18:19
Joined
Jun 21, 2011
Messages
5,899
Either that or use Late Binding. Have you tried your sample code with Outlook open?
 

GinaWhipp

AWF VIP
Local time
Today, 18:19
Joined
Jun 21, 2011
Messages
5,899
So you have a *Me.Combo18.Column(2)*? If not, then replace that with what Control is on your Form.
 

ethan.geerdes

Registered User.
Local time
Today, 15:19
Joined
Jun 4, 2015
Messages
116
The problem I had was that Outlook wasn't checked under references. I still need help though getting the email to be sent though, It compiles though and asks if Access is allowed to use Outlook though which is more than where I was at. Still gotta get that email in there though.

So I ran the code and am coming up with the error on what you stated with the Me.Combo18.Column(2) and i looked into it and saw that I actually did not have the email addresses added into the query that Me.Combo18 was getting it's data from. I added the field in the query and just ran it again and got an error stating "object doesn't support this property or method".
 

GinaWhipp

AWF VIP
Local time
Today, 18:19
Joined
Jun 21, 2011
Messages
5,899
Please post the code, in its entirety, of what you are using now...
 

ethan.geerdes

Registered User.
Local time
Today, 15:19
Joined
Jun 4, 2015
Messages
116
Code:
 Private Sub Command12_Click()

DoCmd.GoToRecord , , acNewRec

  Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
        .Subject = "Test Message"
        .Body = "Body Text"
        .Recipients.to = Me.Combo18.Column(2)
        .Recipients.ResolveAll
        .Display
    End With

End Sub
 

GinaWhipp

AWF VIP
Local time
Today, 18:19
Joined
Jun 21, 2011
Messages
5,899
Try...
Code:
 Private Sub Command12_Click()

  DoCmd.GoToRecord , , acNewRec

  Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
        .Subject = "Test Message"
        .Body = "Body Text"
        .To = Me.Combo18.Column(2)
        .Recipients.ResolveAll
        .Display
    End With

End Sub
 

Users who are viewing this thread

Top Bottom