Change name of pdf report to reflect record number

MichaelWaimauku

Registered User.
Local time
Tomorrow, 09:57
Joined
Dec 6, 2012
Messages
57
I have a report that is attached to an email as a pdf doc. It is a generic name currently and it's been pointed out to me that it would be better for the name to have the issue number in it's name, e.g. "Non Conformity 34.pdf".

This number would be taken from the field NonConformID on the current record. How can I change this to pick up the current number instead of the current FILENAME = "C:\Issue Detals.pdf"???

Current code below:


Code:
Private Sub Email_Click()
If IsNull(Me.NonConformID) Then
   'MsgBox "Yo! We need at least first 8 fields completed", vbCritical
   MsgBox "No data entered onto form", vbCritical
 Else
 Me.Dirty = False
    Dim FILENAME As String
    DoCmd.OpenReport "nonconformity", acViewPreview, , "[nonconformid] =" & Me.NonConformID
    [COLOR=red][B]FILENAME = "C:\Issue Details.pdf"[/B][/COLOR]
    DoCmd.OutputTo acOutputReport, , acFormatPDF, FILENAME, False
    DoCmd.Close acReport, "NonConformity", acSaveNo
    Call SendEmail(FILENAME)
    'MsgBox "Action Successful."
    Exit Sub
End If
End Sub
Private Sub SendEmail(FILENAME As String)
    Dim olApp As Object
    Dim objMail As Object
    Dim olMail As Object
    On Error Resume Next         'Keep going if there is an error
    Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
    If Err Then 'Outlook is not open
        Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
    End If
    Set objMail = olApp.CreateItem(olMailItem)
    With objMail
        .BodyFormat = olFormatHTML
        .To = Forms![nonconformity]![Contact]
        .Attachments.Add FILENAME
        .Display
    End With
    
[COLOR=red][B]    Kill "C:\Issue Details.pdf"[/B][/COLOR]
End Sub

Any help appreciated :-)
 
I managed to sort it out...

Code:
FILENAME = "C:\Non Conformity Issue No. " & [NonConformID] & ".pdf"

Appears to be working ok
 

Users who are viewing this thread

Back
Top Bottom