Results 1 to 5 of 5
  1. #1
    maxbre is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    38

    send email from a form

    This code

    DoCmd.SendObject _ acSendReport, _ "myreport", _ acFormatRTF, _ "recipient@you.com", _ , _ , _ "Subject", _ "Message", _ False

    is how to send the output of the report named "myreport" via e-mail.

    I want to put this code in a command button OnClick event procedure in a form - quite easy up to now -. The problem is that I want to limit the records to be sent by email to just the one that is presently displayed by the form and not all of them.

    I’ve been doing something like this in order to send just one record of a report to the printer by the following code

    Private Sub cmdPrint_Click()
    Dim strWhere As String
    If Me.Dirty Then 'Save any edits.
    Me.Dirty = False
    End If
    If Me.NewRecord Then 'Check there is a record to print
    MsgBox "Select a record to print"
    Else


    strWhere = "[ID] = " & Me.[ID]
    DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
    End If
    End Sub

    Is it possible to modify the first bit of code (send the email) in order to limit the record to be sent by a clause where (which is apparently not supported by “sendobject”)?
    Any help for this?

    thanks

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    I would tend to think that one might focus on making the record source of the report be of just that one record - rather than solving it via vb. Have you looked at this?

  3. #3
    maxbre is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    38
    ...yeah, may be that could be a solution but how would you do that?

    keep in mind that my purpose is to have the possibility to send via email the content of a single record displayed in the form (which obviously is not always the same)

    can you give me some hints to accomplish for this?

    thank you for your reply

  4. #4
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    well when one just opens the Report - you want it to show just one record - probably the one appearing on the form one is looking at. This is very common. There is 2 approaches - one is in the opening argument of the report and the other is to put criteria in the record source query that is calling the ID value from the form control. The latter is generally simpler.

  5. #5
    maxbre is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    38
    thanks ntc

    just after my reply I realised that limiting the record source via a query calling the id value from the control was the simpler approach (but the aftermath was that I had to set up another report for this specific purpose). In my very first attempt I was trying to hit the steepest road...
    thanks again for your feedback

    ps I'm still curious to find a solution for the harder approach (a merge of the two vba codes above mentioned)

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

Similar Threads

  1. How can I send an email from access???
    By Asma in forum Programming
    Replies: 2
    Last Post: 12-07-2011, 07:49 AM
  2. Send in Email Body vice Attachment
    By cassidym in forum Programming
    Replies: 2
    Last Post: 10-20-2010, 06:21 AM
  3. Send email using SendObject instruction
    By stecco in forum Access
    Replies: 4
    Last Post: 09-09-2009, 01:55 AM
  4. Replies: 1
    Last Post: 05-01-2009, 07:33 AM
  5. Beginner trying to send email with attachment
    By ahm in forum Programming
    Replies: 2
    Last Post: 03-24-2009, 08:51 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