Results 1 to 6 of 6
  1. #1
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107

    Auto generate email to send report with parameters

    I have a list box on a form that lets me choose invoices that I want to print. This is the code is use to create the parameter that lets me print just the selected invoices in the list box:

    Dim strwhere As String
    If (IsNull(List9.Value) And List9.ItemsSelected.Count = 0) Then 'NO ORDERS SELECTED
    strwhere = ParseWhere
    Else
    Dim I As Variant
    strwhere = ""
    For Each I In List9.ItemsSelected
    strwhere = strwhere & "ord_no = '" & List9.ItemData(I) & "'" & " OR "
    Next
    strwhere = Left$(strwhere, Len(strwhere) - 3)


    End If

    DoCmd.OpenReport "Order Confirmation", acPreview, , strwhere

    This is fairly simple and straightforward and works great.

    Now I want to create a button that will allow the user to send this report with parameters in an auto generated email. I would like to use the DoCmd.SendObject acSendReport statement for this, but from what I have gathered I cannot attach a report with parameters using this method. Can someone guide me to a solution?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    you would only send the report,
    the query of the report would have the params.

    Are the params settings/controls on a form?



    'alter the query with the criteria....

    Code:
    '----------------
    sub btnOpenQry_click()
    '----------------
    dim sWhere as string 
    dim qdf as querydef
    
    sWhere = " where 1=1"
    if not IsNUll(cboST) then sWhere = sWhere & " and [State]='" & cboST & "'"
    if not IsNUll(cboCity) then sWhere = sWhere & " and [city]='" & cboCity & "'"
    if not IsNUll(cboZip) then sWhere = sWhere & " and [ZipCode]='" & cboZip & "'"
    
    set qdf = currentdb.querydefs("qsMyQry")
    qdf.sql = "Select * from table " & swhere
    qdf.close
    docmd.openquery qdf.name
    
    end sub

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    You can actually use SendObject right after the OpenReport line. It will (should) send the filtered report. So your code would be

    DoCmd.OpenReport "Order Confirmation", acPreview, , strwhere
    DoCmd.SendObject...
    DoCmd.Close... 'close the report here
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    The parameters are not saved on the form. Is there a way to reference selected items in a listbox in a query? I couldn't find a way.

    I will have to study up on querydefs because I have never used them. Thank you for the information.

  5. #5
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    WOW! That worked! Thank you, pbaldy, for a very simple solution!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Auto email generate
    By nherbert31 in forum Queries
    Replies: 4
    Last Post: 08-01-2017, 12:38 PM
  2. Replies: 5
    Last Post: 09-14-2015, 07:24 AM
  3. Replies: 6
    Last Post: 03-19-2014, 03:53 PM
  4. Replies: 4
    Last Post: 02-05-2014, 04:05 PM
  5. Replies: 8
    Last Post: 12-07-2013, 05:22 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