Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2005
    Posts
    28

    Question Unanswered: Emailing Reports

    I am trying to send my report "WarrantyReminder" automatically by email when I click a button. I am using the code below which is opening up an email with the report attached.

    Using the code below I can only send the email to "email@address.co.uk". I would like a different email address to be automatically entered from my active form [forms]![DataEntryForm]![Email] each time I press the button. How do I do this?


    Dim strToWhom As String
    Dim strSubject As String
    Dim strMsgBody As String

    strSubject = "VisionBase Warranty"
    strToWhom = "email@address.co.uk"
    strMsgBody = "Hello"

    DoCmd.SendObject _
    acSendReport, _
    "WarrantyReminder", _
    acFormatSNAP, _
    strToWhom, _
    , _
    , _
    strSubject, _
    strMsgBody, _
    True


    Also I would like to include HTML text in the MsgBody. How do I do this?

    Look forward to hearing from you

    Kind Regards
    John Pietrzak

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Change your variables:

    strSubject = Subject Here
    strToWhom = Recipient Here
    strMsgBody = Body Here



    I'm guessing this is someone else's code?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Apr 2004
    Posts
    173

    Side light to this issue

    I've been happily using the docmd.sendobject to run and send a report to several addresses inside a loop. The other day the routine I've been using for months pops off with an error claiming the machine is out of memory. Has anybody else had this happen.

    A little research turned up an error with docmd.sendobject but none of the descriptions of failure seemed to match what was happening to me. Any thoughts?

  4. #4
    Join Date
    Apr 2005
    Posts
    28

    Question

    Please can you help me with the code for extracting the email address on my form into my email?

  5. #5
    Join Date
    Jul 2004
    Location
    Southampton, UK
    Posts
    368
    Quote Originally Posted by mmbosman
    I've been happily using the docmd.sendobject to run and send a report to several addresses inside a loop. The other day the routine I've been using for months pops off with an error claiming the machine is out of memory. Has anybody else had this happen.

    A little research turned up an error with docmd.sendobject but none of the descriptions of failure seemed to match what was happening to me. Any thoughts?
    Are you hijacking this thread ? Try posting the question in a new thread and add the offending code.
    Chris

  6. #6
    Join Date
    Jul 2004
    Location
    Southampton, UK
    Posts
    368
    Quote Originally Posted by JohnPietrzak
    Please can you help me with the code for extracting the email address on my form into my email?
    I don't mean to sound rude John but you've pretty much spelt out the answer. The fact you've asked the question implies you have no idea what your code means. It would be worth looking up sendobject in Access help as it will explain how it works.

    As Teddy implied, the following line is the big clue:
    strToWhom = "email@address.co.uk"

    so change it to something like this will most likely sort your problem:
    strToWhom = [forms]![DataEntryForm]![email]

    hth
    Chris

  7. #7
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Emailing slow

    You could also try Blat which is an open-source, low overhead emailing program that's pretty simple to intall. The code in MSAccess is fairly easy also.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  8. #8
    Join Date
    Apr 2005
    Posts
    28

    Question

    How do I include a field from form in the MsgBody of the email?

  9. #9
    Join Date
    Jun 2002
    Location
    Mpls/St.Paul area
    Posts
    303
    Hi John

    Keep reading howey's answers. He is right on. The way to include text from a control on the form was part of his answer. You need to know the name of the form and the name of the control. Look at the design view of the form, determine what the name of that control is. If it is txtMyControl, then the way to refer to it is either, My.txtMyControl. Or [Forms]![MyForm]![txtMyControl]. Once you know what to call it, then you can refer to the contents when you send an email.

    strMsgBody = [Forms]![MyForm]![txtMyControl].
    John
    This is the day the Lord has made, I will rejoice and be glad in it.

  10. #10
    Join Date
    Apr 2005
    Posts
    28
    Brilliant! Thanks for your help everyone! I did try that before but for some reason it wasn't working?

  11. #11
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Blat

    Here's an excerpt from code to use with Blat. Like I said, it is a very user-friendly program. If anyone has any other feedback on this, I'd like to hear it. We found this program to be extremely useful (especially in a citrix environment where you don't want to load outlook for the client.)

    Including the form field for the message would simply be populating the subject or body to a variable.

    Public Sub SendEmail(ToVar As String, EmailAttch As String, PONumber As Variant)
    Dim FromVar, Server, FileToSend, OverrideBody, Subject As String
    FromVar = GetUser() & "@weccusa.org"
    Subject = "POReportEmail - " & PONumber
    OverrideBody = "Purchase Order Billed To Muni/Co-op"
    Server = "linux2.weccusa.org"
    FileToSend = "\\SQLServer\Databases\Databases\blatEmail\message .txt"

    Dim x As String

    'send email

    p_blat_location = "\\SQLServer\Databases\Databases\blatEmail\blat.ex e"

    'MsgBox (Attachment)
    'MsgBox EmailAttch

    x = p_blat_location & " " & FileToSend & " -s " & Chr(34) & Subject & Chr(34) & _
    " -t " & ToVar & " -f " & FromVar & " -server " & Server & " -attach " & EmailAttch

    'x = p_blat_location & " " & FileToSend & " -s " & Chr(34) & Subject & Chr(34) & _
    ' " -t " & ToVar & " -f " & FromVar & " -server " & Server & " -attach \\SQLServer\Databases\Databases\PurchaseOrders\POE mails\17725.snp"

    If Len(OverrideBody) > 0 Then
    x = x & " -body " & Chr(34) & OverrideBody & Chr(34)
    End If

    'debug
    x = x & " -debug -log c:\blat.log -timestamp"

    'MsgBox x
    'Debug.Print x

    'Shell x, vbHide

    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run "cmd.exe /c " & x, 0, True
    Set WshShell = Nothing

    End Sub
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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