Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Toasty is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2014
    Location
    The Netherlands
    Posts
    18

    Adding report content into e-mail Body

    Hello,



    I am trying to work my way into putting the content of my report into the body of an e-mail. I have used the following code to do so but I keep on getting the error: "An Expression You Entered Is the Wrong Data Type for one of the Arguments"


    Code:
    Private Sub Command278_Click()
     On Error GoTo ER
     Dim db As Database
     Dim rstOpenPurchaseOrders As Recordset
     Dim strSQL As String
     Dim strSubject, strBody, strAddresses As String
     Set db = CurrentDb()
     strSQL = "SELECT * FROM qry_POOpenOrdersPerVendor;"
     Set rstOpenPurchaseOrders = db.OpenRecordset(strSQL, dbOpenDynaset)
     If Not rstOpenPurchaseOrders.EOF Then
     strBody = "blah blah blah" & vbCrLf & vbCrLf
     strBody = strBody & "Partnumber" & vbCrLf
     strBody = strBody & "==========" & vbCrLf
     rstOpenPurchaseOrders.MoveFirst
     Do While Not rstOpenPurchaseOrders.EOF
     strBody = strBody & rstOpenPurchaseOrders![po_partnr] & vbCrLf
                           rstOpenPurchaseOrders.MoveNext
              Loop
          End If
          strSubject = "Here's my report!"
          strAddresses = "look.look@nmhg.com"
          DoCmd.SendObject acSendNoObject, , acFormatTXT, Me.E_mail_Adress, , , strSubject, strBody, True
          Exit Sub
    ER:
         MsgBox Err.Number & " " & Err.Description
         Exit Sub
     End Sub
    I am clueless.

    Thanks all!

    Best Regards,

    Toasty

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    It helps if you tell readers where the error is occurring, what line of code. You can determine this by using the Debug option when the Run Time Exception occurs.

    I would think it would work anyway but, you may want to change
    Dim strSubject, strBody, strAddresses As String

    to
    Dim strSubject As String
    Dim strBody As String
    Dim strAddresses As String

  3. #3
    Toasty is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2014
    Location
    The Netherlands
    Posts
    18
    I can not get the debug to work. As you said it would be a lot more easy if the line is marked that creates the error but when the error occurs, I can not start the debug mode.

    Your tip to separate the string reference does not work. I get the same error. How can I start the debug mode?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Disable the error handler code until the procedure runs properly. Comment the On Error GoTo line.

    Review link at bottom of my post for debug guidelines.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Toasty is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2014
    Location
    The Netherlands
    Posts
    18
    Thanks June7! It works. My Debugging quest found out that there is nothing wrong with the code, but if there are a lot of lines, the code simply can not process the data. So now I have to find a way to filter my query in a report or form. I know that a report does not filter a query. This is not the correct thread to ask this. Thanks all for the help!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Too much data for email - that's a new one. How will filtering report data help you with this email? I presume the recordset query is already filtered to the dataset you need to transmit.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Toasty is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2014
    Location
    The Netherlands
    Posts
    18
    Well the people working with the report are able to filter the report in the report view. It can have a lot of rows, to sometimes they filter on (by example Partnumber): Equals " 00001 ". When they do this they get the correct partnumbers and can mail the results. Due to the fact that my code links to the underlaying query and not to the report itself, the complete dataset will be set up in the e-mail. Is there a way to filter the query in the report (and ofcourse not when running the report but when the report is already shown)? That would fix two problems! Thanks

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Perhaps a debug.print line of strBody here would be beneficial

    Code:
     Do While Not rstOpenPurchaseOrders.EOF
     strBody = strBody & rstOpenPurchaseOrders![po_partnr] & vbCrLf
                           rstOpenPurchaseOrders.MoveNext
              Loop

  9. #9
    Toasty is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    The Netherlands
    Posts
    18
    I have added a filter option like this one in my query:
    Code:
    popartnrfilter: (IIf([Forms]![frm_POOpenOrdersPerVendor]![poPartnrFilter] Is Null,True,[po_partnr]=[Forms]![frm_POOpenOrdersPerVendor]![poPartnrFilter]))
    With the following criteria:
    Code:
    <>False
    This allows me to filter my query by using an unbound field in my form. The filtering works perfect. But when I try to export the data to outlook this results in the following error: 3061 too few parameters. Expected 1.

    Could it be related to the "updating" of my recordset?

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Don't use Is Null in IIf() expression, use IsNull.

    IIf(IsNull([Forms]![frm_POOpenOrdersPerVendor]![poPartnrFilter])
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    Toasty is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    The Netherlands
    Posts
    18
    Hi June,

    I tried it but unfortunately without success. I think is has something to do with my first code and the updating of my recordset due to the filtering of my query after the form is run. Could that has something to do with it?

    Thanks.

  12. #12
    Toasty is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    The Netherlands
    Posts
    18
    To make things more clear, here is my file: TestFile.zip

    I really hope someone can help me.

    Best regards,

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Something looks strange to me with your code. Maybe if you looked closer at it. Have you tried debugging?

    Code:
    Do While Not rstOpenPurchaseOrders.EOF
     strBody = strBody & rstOpenPurchaseOrders![po_partnr] & vbCrLf
                           rstOpenPurchaseOrders.MoveNext
              Loop
          End If
          strSubject = "Here's my report!"

  14. #14
    Toasty is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    The Netherlands
    Posts
    18
    Yes I did and the error occurs in this line:
    Code:
     Set rstOpenPurchaseOrders = db.OpenRecordset(strSQL, dbOpenDynaset)
    Again, everything was fine, untill I tried to filter the query after the form was loaded.

  15. #15
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I doubt this line has anything to do with the properties of your Form
    Set rstOpenPurchaseOrders = db.OpenRecordset(strSQL, dbOpenDynaset)

    However, setting your form aside, you could try
    Set rstOpenPurchaseOrders = db.OpenRecordset(strSQL, dbOpenSnapshot)

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 17
    Last Post: 07-15-2014, 06:17 AM
  2. E-Mail code adding #mailto:
    By SMcGrath in forum Programming
    Replies: 2
    Last Post: 12-23-2013, 11:47 AM
  3. Replies: 5
    Last Post: 10-29-2012, 05:53 AM
  4. Replies: 1
    Last Post: 09-14-2012, 10:27 AM
  5. Replies: 1
    Last Post: 05-18-2011, 09:18 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