Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email record from form

Status
Not open for further replies.

tonyx666

MIS
Apr 13, 2006
214
GB
i want to place a button on my form

when it is pressed..

a message box opens and says

Please enter the recipients email address:

so you enter an email address

press ok

then selected fields and their values

(from the record that is opened obviously)

are transfered into a customized email template

and emailed to the supplied email address


HOW CAN I MAKE THIS?

London Heathrow Cars
 
Hi! For some ideas, take a look at this thread:

You will need to customize it to your situation, and you will need a line in the code like this to set the email address:

Code:
strEmailAddress = InputBox$("Enter the Email recipient's address.","Email Address")
[code]

You will need variables to capture the values of whatever controls you have on the active record, but maybe this is enough to get you started.

Hope this helps.

Tom

[COLOR=green]Born once die twice; born twice die once.[/color]
 
ok, i have had some help from another forum, and i have this so far.. this is the code on my form.. the cmdSendFields button is clicked..

Code:
Option Compare Text

Option Explicit


Private Sub cmdSendFields_Click()
SendFields "BOOKINGS", "bookingid", Me!bookingid, _
               "refno", _
               "jobday", _
               "jobdate", _
               "jobtime", _
               "pickup", _
               "destination", _
               "cartype", _
               "fcjobprice"
End Sub

and then using the below module, the fields above are emailed.

Code:
Option Explicit
Option Compare Text

Private Const conTestEmailAddress As String = "tonyx666@mail.com"


Public Sub SendFields(ByVal strTableName As String, _
                      ByVal strPKName As String, _
                      ByVal lngIndex As Long, _
                 ParamArray vntFieldNames() As Variant)

    Dim intIndex As Integer
    Dim strBody As String
    Dim strSQL As String
 
    strSQL = "Select * From " & strTableName & " Where " & strPKName & " = " & lngIndex
    
    With CurrentDb.OpenRecordset(strSQL, 2)
        For intIndex = LBound(vntFieldNames) To UBound(vntFieldNames)
            strBody = strBody & .Fields(vntFieldNames(intIndex)) & vbNewLine
        Next intIndex
    End With
    
    SendEmail conTestEmailAddress, _
              "Confirmation.", _
              strBody
              
End Sub


Public Sub SendEmail(ByVal strTo As String, _
                     ByVal strSubject As String, _
                     ByVal strBody As String, _
                ParamArray vntAttachments() As Variant)

    Dim intIndex As Integer
    
    With CreateObject("Outlook.Application").CreateItem(0)
        .To = strTo
        .Subject = IIf(Len(strSubject), strSubject, "No subject transmitted.")
        .Body = IIf(Len(strBody), strBody, "No body transmitted.")
        
        For intIndex = LBound(vntAttachments) To UBound(vntAttachments)
            If Len(vntAttachments(intIndex)) Then .Attachments.Add vntAttachments(intIndex)
        Next intIndex
        
        .Send
        
        MsgBox "Message to..." & vbNewLine & _
               strTo & vbNewLine & _
               "has been sent."
    End With
    
End Sub

this is fine, however, at the moment the email just sends details like so

ABC45
Sunday
06/06/06
6.00pm
address1
address2

YOU GET THE PICTURE

i just want to know how i can edit the module code so i can make certain items bold.. maybe use a table layout and include a graphic.. etc, ideally i would like to create a html template in outlook, and then leave haps for the positions to be filled..

if anyone could give me any advice i would be most grateful

London Heathrow Cars
 
I will probably lurk and learn on this one. When you send your file to Outlook, you can specify Rich Text format using the olFormatRichText constant (I think), but beyond that I haven't a clue how to help.

Tom

Born once die twice; born twice die once.
 
You may also simply consider the DoCmd.SendObject method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top