Closing form with code

Sketchin

Registered User.
Local time
Today, 08:12
Joined
Dec 20, 2011
Messages
580
I have this code that is under an "Email Invoice" command button. It works fine, as in, when clicked, it opens a form to the current invoice, converts it to a PDF and attaches to an email.

The first problem is that I can't get the Close Form code to actually close the form.

The Second problem is that the MyFileName code is not naming the filename the way I would like. It is just naming it Tecterra Invoice.PDF, rather than 2013-GL0001-Tecterra Invoice (Which is how the subject looks)

Code:
Subject = Me.txtInvoiceNumber & "-" & "Tecterra Invoice" & ".pdf"
MyFileName = " & Me.txtInvoiceNumber & " & "-" & "Tecterra Invoice" & ".pdf"
    
  
    ' Open Invoice form in preview mode
    DoCmd.OpenForm "frmrptCurrentRecordInvoice", acNormal, , "[InvoiceID]= forms!frmInvoicing![InvoiceID]"
    ' Send a PDF of the form to an email
    DoCmd.SendObject acForm, "frmrptCurrentRecordInvoice", "PDFFormat(*.pdf)", "", "", "", Subject, "Hello,  attached you will find a PDF of your current TECTERRA invoice.", True, ""
    ' Close the form
    DoCmd.Close acForm, "frmrptCurrentRecordInvoice"
 
Your DoCmd.Close looks fine so I'm unsure why that would not be working :confused:

The naming problem may have something to do with your use of the hyphen (-) in the name, try using an underscore (_) instead.
 
Where is there a hyphen?
 
Ahh, in the MyFileName part... thats just a character. Will try _ anyway.

Thanks John
 
I wonder if the export is still working when you try to do the close?

You could try popping a DoEvents command just before the close to see if that will allow the export to finish before trying to close the form.
 
Not familiar with DoEvents...

Tried the _ and it still never worked.
 
If I am understanding your request correctly, you want both the file name and subject to be identical, but your file name is not appending the invoice number to the front of the string?

To me, if they should be the same, you could just use your Subject variable in place of the MyFileName variable. But this seems to be the issue:
Code:
Subject = Me.txtInvoiceNumber & "-" & "Tecterra Invoice" & ".pdf"
MyFileName = [COLOR=red]" &[/COLOR] Me.txtInvoiceNumber & [COLOR=red]" &[/COLOR] "-" & "Tecterra Invoice" & ".pdf"

You seem to have a little bit extra 'stuff' in MyFileName. Remove the bits in red. But if they really are to be the same, remove MyFileName altogether and just refer to Subject.
 

Users who are viewing this thread

Back
Top Bottom