Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2011
    Location
    Rhyl
    Posts
    10

    Unanswered: Send a single record via email

    Hi,

    Does anyone know whether it is possible/how to send a single record via email using a button? I know you can send a complete object such as a form via email, however I need to be able to send individual records.

    I am creating a database for 'Technical Requests'. When a request is entered, it has to be authorised by the Technical Manager, therefore I need a button on the form that can send the request to the Manager when entered.

    Hope somebody can help!!! Thanks!

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Quote Originally Posted by cefndyengineering View Post
    Hi,

    Does anyone know whether it is possible/how to send a single record via email using a button? I know you can send a complete object such as a form via email, however I need to be able to send individual records.
    Using which format?
    Have a nice day!

  3. #3
    Join Date
    Oct 2009
    Posts
    204
    I use this to send via outlook. The user enters the fields on the form (a single record) then the code takes the record, field by field, and transposes it into the email.

    Code:
        Dim stdocname As String
        Dim stEmail As String
        Dim stEmailcc As String
        Dim stEmailbcc As String
        Dim stSubject As String
        Dim stbody As String
        
        stdocname = "frm_ServiceRequestSubmit"
        
        stEmail = Me.Email1 & ";" & Me.Email2
        
        stEmailcc = "address@domain.com; address2@domain.com"
        
        stSubject = "Service Request For " & Me!RequestedName & "," & Me!RequestDate
        
        stbody = ("New service request submitted by:  " & vbCrLf & _
        Me!RequestedName & " On " & Me!RequestDate & vbCrLf & _
        vbCrLf & _
        "Service Type:  " & Me!ServiceTypeCombo & vbCrLf & _
        "Problem:  " & Me!Combo61 & vbCrLf & _
        vbCrLf & _
        "Description:  " & Me!Description & vbCrLf & _
        vbCrLf & _
        Me!HotText & vbCrLf & _
        vbCrLf & _
        "Requested completion by:  " & Me!CompletedBy)
        
        DoCmd.SetWarnings False
        DoCmd.SendObject acSendNoObject, , , stEmail, stEmailcc, , stSubject, stbody, , False
        DoCmd.SetWarnings True

  4. #4
    Join Date
    Oct 2011
    Location
    Rhyl
    Posts
    10
    Sorry, I don't really understand!!

    I don't know what you mean by which format?

    And that code didn't work ...but I don't really understand visual basic code either...guess I'm still a newbie with all this.

  5. #5
    Join Date
    Oct 2009
    Posts
    204
    That code is an example, it wouldn't work for you without modifying it to fit your database.

    Here is how it works

    On my form (frm_ServiceRequestSubmit) for submitting a service request, there are these fields:
    Email
    Email2
    RequestedName
    RequestDate
    ServiceTypeCombo
    Combo61
    Description
    HotText
    CompletedBy

    Wherever it says Me![FieldName], that refers to a field on the form you are referring to

    Wherever it says "vbCrLf & _" this tells the code to continue the same expression but to go to the next line

    These name the variables
    Code:
        Dim stdocname As String
        Dim stEmail As String
        Dim stEmailcc As String
        Dim stEmailbcc As String
        Dim stSubject As String
        Dim stbody As String
    This defines the variable "stdocname" as the form I am emailing out of
    Code:
        stdocname = "frm_ServiceRequestSubmit"
    This defines the variable "stEmail" as the subject To: line of the email. It pulls two fields on the form in which are typed email addresses.
    Code:
        stEmail = Me.Email1 & ";" & Me.Email2
    This defines the variable "stEmailcc" as the cc: line of the email. I had in here two fixed email addresses who were always copied - I removed those.
    Code:
        stEmailcc = "address@domain.com; address2@domain.com"
    This defines the variable "stSubject" as the Subject line of the email.
    Code:
        stSubject = "Service Request For " & Me!RequestedName & "," & Me!RequestDate
    This defines the variable "stBody" as the body of the email.
    Code:
        stbody = ("New service request submitted by:  " & vbCrLf & _
        Me!RequestedName & " On " & Me!RequestDate & vbCrLf & _
        vbCrLf & _
        "Service Type:  " & Me!ServiceTypeCombo & vbCrLf & _
        "Problem:  " & Me!Combo61 & vbCrLf & _
        vbCrLf & _
        "Description:  " & Me!Description & vbCrLf & _
        vbCrLf & _
        Me!HotText & vbCrLf & _
        vbCrLf & _
        "Requested completion by:  " & Me!CompletedBy)
    This is the code that sends the email. It also turns warnings off before executing, and turns them back on afterward.

    Code:
        DoCmd.SetWarnings False
        DoCmd.SendObject acSendNoObject, , , stEmail, stEmailcc, , stSubject, stbody, , False
        DoCmd.SetWarnings True
    Basically it comes up looking like this:

    To: [Email1]; [Email2]
    cc: address@domain.com; address2@domain.com
    Subject: Service Request For [RequestedName], [RequestDate]

    Body:
    New service request submitted by:
    [RequestedName] On [RequestDate]

    Service Type: [ServiceTypeCombo]
    Problem: "[Combo61]

    Description: [Description]

    [HotText]

    Requested completion by: [CompletedBy]



    I hope this helps.

  6. #6
    Join Date
    Nov 2011
    Posts
    413

    Send Email using a command button

    Quote Originally Posted by cefndyengineering View Post
    Hi,

    Does anyone know whether it is possible/how to send a single record via email using a button? I know you can send a complete object such as a form via email, however I need to be able to send individual records.

    I am creating a database for 'Technical Requests'. When a request is entered, it has to be authorised by the Technical Manager, therefore I need a button on the form that can send the request to the Manager when entered.

    Hope somebody can help!!! Thanks!
    Macro Name Action

    Employee Report SelectRecord Object Type Object Name
    SelectObject Report Employee Report
    In Database Window No
    RunCommand Print (send to pdf printer)



    Substitute the Runcommand For This

    SelectObject
    RunCommand


    Then choose your printer as a pdf


    Or:
    Send to word

    Macro Name
    Estimate SendObject Report
    Object Name RMothStatmnt
    Output Format Rich Text Format
    Edit Message Yes

    RunCommand Close
    SetWarnings No

  7. #7
    Join Date
    Oct 2011
    Location
    Rhyl
    Posts
    10
    Thank you both so much, finally got the hang of it! Feel like I'm finally starting to turn a corner with this Visual Basic stuff!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •