Results 1 to 5 of 5
  1. #1
    Rhene is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    3

    Command buttons- connecting outlook to few different buttons

    Hi All

    I have a form that has 3 different email fields and 3 buttons to open each of them. Problem is I have only one of them working the rest is kinda adapting the first ones event:/
    when I am trying to set up the other buttons and I add the event procedure in properties the below code for the working button is already there with the same command, if I delete it and replace it, the other button stops working and so on. Would appreciate help. All I do is intuitive when it comes to this part of access and on a trial basis Am I adding the new event the wrong way? Should I do something else (talk in big letters to me about code and what to do in the VBA cus I have no clue!)


    The below is the code for the working one, and works perfectly. Launches outlook and inputs the appropriate email address into the send to field:

    Option Compare Database

    Private Sub Command1215_Click()
    Call Sendemail
    End Sub
    Sub Sendemail()
    Dim oOutlook As Outlook.Application

    Dim oEmailItem As MailItem


    ' prevent 429 error, if outlook not open
    On Error Resume Next
    Err.Clear
    Set oOutlook = GetObject(, "Outlook.application")
    If Err.Number <> 0 Then
    Set oOutlook = New Outlook.Application
    End If

    Set oEmailItem = oOutlook.CreateItem(olMailItem)
    With oEmailItem
    .To = [OWNER EMAIL]
    .Display
    End With
    Set oEmailItem = Nothing
    Set oOutlook = Nothing

    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    You can send email with a single statement:
    docmd.sendObject.....

  3. #3
    Rhene is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    3
    Thank you for replying ranman256, how do I connect that single statement to the appropriate field to retrieve the email? Mind you are talking to a VBA todler

  4. #4
    Rhene is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    3
    The attached image shows what is in code builder when I launch it for the next command button. Shouldn't this be empty? It shows the code for the other one and at the end is the start for the new command but when I add new code below then nothing works and an error comes up. And if I attempt to delete the first code and adjust it the new button works the other one stops...Shouldn't they be separate?

    I just need the buttons to launch a new message and input email address from the appropriate field, for the user to do the rest.


    Click image for larger version. 

Name:	Capture2.PNG 
Views:	7 
Size:	28.1 KB 
ID:	27113

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Google the syntax for SendObject. As Arnie says, you can send the email in one line. For each of your command buttons you will have that in your OnClick event procedure. An example I use is:
    DoCmd.SendObject acSendNoObject, , , Me!EmailAddr, , , EmSubj, EmBody - where I have created the subject and the body in strings beforehand and the email address comes from the form.

    Notes: Under Option Compare Database at the top, add a new line, Option Explicit. Go to Tools>Options and set Require Variable Declaration. This will help you with getting the code correct. Also, don't keep Access's names for fields and objects. Command### is meaningless, give them real names.

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

Similar Threads

  1. command buttons
    By hijack61 in forum Access
    Replies: 4
    Last Post: 11-19-2011, 04:59 PM
  2. Command Buttons
    By BLD21 in forum Access
    Replies: 2
    Last Post: 05-10-2011, 06:27 AM
  3. Command Buttons
    By Rosier75 in forum Access
    Replies: 3
    Last Post: 03-09-2011, 11:59 AM
  4. command buttons
    By nashr1928 in forum Forms
    Replies: 23
    Last Post: 10-15-2010, 04:09 PM
  5. Command buttons
    By maintt in forum Forms
    Replies: 3
    Last Post: 08-03-2010, 09:52 AM

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