I have a form containing a subform sfmDebtorsList with information about customers who have elected to receive Statements by email. A command button on the main form initiates creating the email and saving the attachment. The process works fine when customers have company names like Smith Ltd, but gives an Output to error if the name is Smith Ltd T/A Jones Ltd. It's the forward slash / that's causing it.
The relevant section of code is this, with the line DoCmd.OutputTo acOutputReport causing the problem. The names need to stay as they are so how is it best to get round the trip-up?
Code:
'Create folder for statements unless it's already there
path = "\\MOAKBBTERM16\Database\Statements\"
If Len(Dir(path, vbDirectory)) = 0 Then MkDir path
'Define recipient
strBody = "To : " & Me.sfmDebtorsList.Form.Payee & "<BR><BR> Please find attached your latest statement. <BR><BR> Our terms : Payment by 15th day of the month"
'Define where to save a copy
FileName = Me.sfmDebtorsList.Form.SearchName
FilePath = "\\MOAKBBTERM16\Database\" & FileName & ".pdf"
path = path & FileName & ".pdf"
'Save this statement
DoCmd.OutputTo acOutputReport, "rptDebtorSingleStatement", acFormatPDF, path
'Create temporary file
DoCmd.OutputTo acOutputReport, "rptDebtorSingleStatement", acFormatPDF, FilePath