Results 1 to 3 of 3
  1. #1
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186

    How to add a criteria "Name change" for a DoCmd.SendObject

    HI everyone,

    Quick question...

    I have created a "send button" to send a Report as pdf, what I want is to change the name based on a textbox (Unique Code by record)

    The name added is the "Report_Name_by_default" and I want to add the name according to the Textbox: Me.Code


    This is my VB Code



    Private Sub EnviarReportePDFcmd_Click()



    On Error GoTo Err_EnvioReportecmd_Click

    Dim rst As DAO.Recordset
    Dim cadenacontactos As String
    Dim NombreReporte As String

    ReportName = "Reporte de No Conformidad " & Me.Code 'This is the name I want to call my file

    Set rst = CurrentDb.OpenRecordset("Select * from Equipo_Trabajo Where LineaProduccion = '" & Me.Linea_Produccion & "'", dbOpenDynaset)

    If rst.EOF = False Then
    rst.MoveLast
    rst.MoveFirst
    Do Until rst.EOF
    cadenacontactos = cadenacontactos & rst!Correos & ";"
    rst.MoveNext

    Loop

    cadenacontactos = Mid(cadenacontactos, 1, Len(cadenacontactos) - 1)

    End If
    rst.Close

    Dim stDocName As String
    stDocName = "NC_Reporte_Completo_Report_PDF"


    'I don't know how to change the name as ReportName; I don't want the default name of the "Report"

    DoCmd.SendObject acSendReport, stDocName, acFormatPDF, cadenacontactos, , , "No Conformidad Folio: " & Me.Code, "Se generó la No Conformidad con Folio: " & Me.Code

    Exit_EnvioReportecmd_Click:
    Exit Sub

    Err_EnvioReportecmd_Click:

    MsgBox "Cancelado", vbExclamation, "Q-Sys Quality Management Tool"

    MsgBox Err.Description
    Resume Exit_EnvioReportecmd_Click

    End Sub

    'Thank you very much for your support!!!!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    use OutputTo to create the file with the correct filename.
    then send it as an attachment via Outlook (or other email)

    sub MakeRpt()
    vRpt ="Reporte de No Conformidad " & Me.Code 'This is the name I want to call my file
    vFile = "c:\folder" & vRpt & ".pdf"

    'put the report into a file
    docmd.OutputTo acOutputReport ,"rMyReport",acFormatPDF,vFile

    'send that file
    Send1Email "bob@aol.com", "your report","here is the report", vfile

    end sub

    Code:
    
    
    Code:
    
    '-------
    'YOU MUST ADD THE OUTLOOK APP IN REFERENCES!!!   checkmark OUTLOOK OBJECTS in the vbE menu, Tools, References
    '-------
    Public Function Send1Email (ByVal pvTo, ByVal pvSubj, ByVal pvBody, optional pvFile ) As Boolean
    Dim oApp As Outlook.Application
    Dim oMail As Outlook.MailItem
    On Error GoTo ErrMail
    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.CreateItem(olMailItem)
    With oMail
        .To = pvTo
        .Subject = pvSubj
        .Body = pvBody
        if not IsMissing(pvFile) then .Attachments.Add pvFile, olByValue, 1
        
       .Send
    End With
    Email1 = True
    Set oMail = Nothing
    Set oApp = Nothing
    Exit Function
    ErrMail:
    MsgBox Err.Description, vbCritical, Err
    Resume Next
    End Function

  3. #3
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Hi ranman256

    Thank you very much for your support!

    I am not a full expert coding so what I do was this but did'nt work, could you tell me what's wrong?

    (I added your code for the Public Send1Email)

    ********************

    Private Sub MakeRpt_Click()


    Dim vRpt As String
    Dim vFile As String
    Dim rMyReport As String


    rMyReport = "Diagrama_CausaEfecto_Report_PDF"
    vRpt = "Reporte de No Conformidad " & Me.ID 'This is the name I want to call my file
    vFile = "c:\folder" & vRpt & ".pdf"


    'put the report into a file
    DoCmd.OutputTo acOutputReport, rMyReport, acFormatPDF, vFile


    'send that file
    'Send1Email "bob@aol.com", "your report", "here is the report", vFile


    End Sub

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

Similar Threads

  1. Replies: 4
    Last Post: 10-02-2019, 04:58 AM
  2. Replies: 3
    Last Post: 07-28-2017, 12:12 PM
  3. Replies: 2
    Last Post: 05-04-2017, 01:10 AM
  4. Replies: 3
    Last Post: 04-20-2016, 02:50 PM
  5. Replies: 30
    Last Post: 09-27-2013, 01:34 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