Results 1 to 7 of 7
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    Please Help Me Fix This Code

    Please Help Me Fix This Code




    Private Sub Command52_Click()
    DoCmd.SendObject acSendReport, "Inventory", acFormatPDF, "xxx@gmail.com", , , "Inventory Ledger " & Date, "Attached please find the Inventory Ledger"
    DoCmd.SendObject acSendReport, "General Purchase", acFormatPDF, "xxx@gmail.com", , , "Selected Titles Purchase Ledger " & Date, "Attached please find the Selected Account Titles Purchase Ledger"
    DoCmd.SendObject acSendReport, "General Sales", acFormatPDF, "xxx@gmail.com", , , "Selected Customer Sales Ledger " & Date, "Attached please find the Selected Customer Sales Ledger"
    DoCmd.SendObject acSendReport, "Employees Salery Ledger", acFormatPDF, "xxx@gmail.com", , , "Selected Employees Salery Ledger " & Date, "Attached please find the Selected Employees Salery Ledger"
    DoCmd.SendObject acSendReport, "Pettycash Detail", acFormatPDF, "xxx@gmail.com", , , "Petty Cash Selected User's Detail " & Date, "Attached please find the Selected Petty Cash Selected User's Detail"
    DoCmd.SendObject acSendReport, "Inventory", acFormatPDF, "xxx@gmail.com", , , "Inventory Ledger " & Date, "Attached please find the Inventory Ledger"
    End Sub

  2. #2
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Maybe it would be helpful if we knew what the error was?

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by aamer View Post
    Please Help Me Fix This Code


    Private Sub Command52_Click()
    DoCmd.SendObject acSendReport, "Inventory", acFormatPDF, "xxx@gmail.com", , , "Inventory Ledger " & Date, "Attached please find the Inventory Ledger"
    DoCmd.SendObject acSendReport, "General Purchase", acFormatPDF, "xxx@gmail.com", , , "Selected Titles Purchase Ledger " & Date, "Attached please find the Selected Account Titles Purchase Ledger"
    DoCmd.SendObject acSendReport, "General Sales", acFormatPDF, "xxx@gmail.com", , , "Selected Customer Sales Ledger " & Date, "Attached please find the Selected Customer Sales Ledger"
    DoCmd.SendObject acSendReport, "Employees Salery Ledger", acFormatPDF, "xxx@gmail.com", , , "Selected Employees Salery Ledger " & Date, "Attached please find the Selected Employees Salery Ledger"
    DoCmd.SendObject acSendReport, "Pettycash Detail", acFormatPDF, "xxx@gmail.com", , , "Petty Cash Selected User's Detail " & Date, "Attached please find the Selected Petty Cash Selected User's Detail"
    DoCmd.SendObject acSendReport, "Inventory", acFormatPDF, "xxx@gmail.com", , , "Inventory Ledger " & Date, "Attached please find the Inventory Ledger"
    End Sub
    to start off with I would store your email in a simple string name to avoid problems

    dim strEmail as string
    strEmail = "xxx@gmail.com"

    this way you can do stuff with it too

    At this point I am guessing you are getting multiple emails instead of attaching them into one email?

    If that is the case send object will send one at a time and cause you problems

    You can use outlook or CDO and make the reports into PDFs (saved onto your c drive) and then attach them all to the same email.

    The user has to have outlook in order for that to work and you need the reference library selected

  4. #4
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    I tried doing the way you suggested

    Private Sub Command52_Click()

    dim strEmail as string
    strEmail = "abc@gmail.com"
    DoCmd.SendObject acSendReport, "Inventory", acFormatPDF, "abc@gmail.com", , , "Inventory Ledger " & Date, "Attached please find the Inventory Ledger"
    DoCmd.SendObject acSendReport, "General Purchase", acFormatPDF, "abc@gmail.com", , , "Selected Titles Purchase Ledger " & Date, "Attached please find the Selected Account Titles Purchase Ledger"
    DoCmd.SendObject acSendReport, "General Sales", acFormatPDF, "abc@gmail.com", , , "Selected Customer Sales Ledger " & Date, "Attached please find the Selected Customer Sales Ledger"
    DoCmd.SendObject acSendReport, "Employees Salery Ledger", acFormatPDF, "abc@gmail.com", , , "Selected Employees Salery Ledger " & Date, "Attached please find the Selected Employees Salery Ledger"
    DoCmd.SendObject acSendReport, "Pettycash Detail", acFormatPDF, "abc@gmail.com", , , "Petty Cash Selected User's Detail " & Date, "Attached please find the Selected Petty Cash Selected User's Detail"

    End Sub

    it only sends Inventory report as attachment.
    where as I want General Purchase, General Sales, Employees Salery Ledger and Pettycash Detail alongwith Inventory Report as attachments in a single email. I don't want them to be saved on c drive first and then send them.

    can you help me with this

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by aamer View Post
    I tried doing the way you suggested

    Private Sub Command52_Click()

    dim strEmail as string
    strEmail = "abc@gmail.com"
    DoCmd.SendObject acSendReport, "Inventory", acFormatPDF, "abc@gmail.com", , , "Inventory Ledger " & Date, "Attached please find the Inventory Ledger"
    DoCmd.SendObject acSendReport, "General Purchase", acFormatPDF, "abc@gmail.com", , , "Selected Titles Purchase Ledger " & Date, "Attached please find the Selected Account Titles Purchase Ledger"
    DoCmd.SendObject acSendReport, "General Sales", acFormatPDF, "abc@gmail.com", , , "Selected Customer Sales Ledger " & Date, "Attached please find the Selected Customer Sales Ledger"
    DoCmd.SendObject acSendReport, "Employees Salery Ledger", acFormatPDF, "abc@gmail.com", , , "Selected Employees Salery Ledger " & Date, "Attached please find the Selected Employees Salery Ledger"
    DoCmd.SendObject acSendReport, "Pettycash Detail", acFormatPDF, "abc@gmail.com", , , "Petty Cash Selected User's Detail " & Date, "Attached please find the Selected Petty Cash Selected User's Detail"

    End Sub

    it only sends Inventory report as attachment.
    where as I want General Purchase, General Sales, Employees Salery Ledger and Pettycash Detail alongwith Inventory Report as attachments in a single email. I don't want them to be saved on c drive first and then send them.

    can you help me with this
    yeah first of all you are doing what I suggest incorrectly.

    Dim strEmail as string <- making a string variable for this function
    strEmail = "abc@gmail.com" <- stuffing a string into strEmail (because it is a string variable and takes strings like "abc@gmail.com")

    "abc@gmail.com" is a string because it has the two " " wrapped around it.

    so

    DoCmd.SendObject acSendReport, "Inventory", acFormatPDF, "abc@gmail.com", , , "Inventory Ledger " & Date, "Attached please find the Inventory Ledger"

    should look like

    DoCmd.SendObject acSendReport, "Inventory", acFormatPDF, strEmail, , , "Inventory Ledger " & Date, "Attached please find the Inventory Ledger"

    The reason we do this is instead of typing "abc@gmail.com" every time you can type strEmail instead because it has the string value of "abc@gmail.com"

    in code it reads top down so it goes and makes the strEmail first

    when you can do that you can wrap a function around it e.g. len(strEmail) which will give you the number of characters in the string - which is 13

    then you can do something like iif(len(strEmail) > 13,bob@gmail.com,sam@gmail.com) <- in programming I swapped the string to be if it is greater than 13 change it to bob@gmail.com else if false make it sam@gmail.com

    now I'm not suggesting you use len() as it won't help you in your code but you can use other functions/methods to do stuff like verify the email is correct etc etc etc.

    If you want to send all the reports in one email you can't use docmd.sendobject

    The reason why is because you are asking one task at a time.

    To get around that you can do one task at a time like open report, export it as a pdf, then save it to your c:/

    then once all reports have been saved you can attach them into your email as file attachments

    To do this you will need to run outlook code which gets more complicated than docmd.sendobject

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    http://social.msdn.microsoft.com/For...t-in-one-email

    this guide explains using outlook

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The issue may be the first email is waiting to be sent before the next Docmd can fire. You might try sending the message without interaction using the False argument.
    DoCmd.SendObject acSendReport, "Inventory", acFormatPDF, "xxx@gmail.com", , , "Inventory Ledger " & Date, "Attached please find the Inventory Ledger", False

    another option might be to SEND the email and see if the code keeps going.

    When I create more than one report, I use Docmd.Outputto and save the PDF's to a temp folder and then create an instance of outlook in VBA, then attach all the PDF's

    Another option might be to not use Outlook and use CDO.

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

Similar Threads

  1. Replies: 4
    Last Post: 03-10-2014, 12:18 PM
  2. Replies: 2
    Last Post: 06-28-2013, 12:58 PM
  3. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  4. Replies: 1
    Last Post: 05-04-2013, 12:19 PM
  5. Word code in Access - How to modify my current code
    By Alexandre Cote in forum Programming
    Replies: 0
    Last Post: 11-15-2010, 08:26 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