Prompt before overwriting a saved file

easygoingdave

Registered User.
Local time
Today, 00:53
Joined
May 22, 2013
Messages
18
The code below successfully saves a .pdf file to my c: drive. However, on occasion i want to overwrite a previously saved invoice e.g. 3815-140515-Bristol with an amended invoice but retain the same Invoice Number e.g. 3815-150515-Bristol.
Currently, if i save the invoice with the same invoice number but a different date it just saves down without overwriting the original invoice. Leaving 2 invoices with the same invoice numbers but with 2 different dates.
What i want to achieve is: Once I hit the SaveInvoice button the code will check that invoice Nr 3815 does not exist in c: drive and save normally. However, if it does exist a msgbox will then prompt me to overwrite. Can any one help?

Current code:

Private Sub SaveInvoice_Click()

'Save Invoice as PDF and annotate invoice number, site name, and date

Dim slFileName As String
' create the invoice as a pdf

slFileName = Me.txtInvoiceNr.Value & "-" & Format(Date, "ddmmyy") & "-" & Me.SiteName.Value & ".pdf"

DoCmd.OutputTo acOutputReport, "rptinvoice", acFormatPDF, ("c:\CompanyName Invoices\Regular Invoices\" & slFileName)

MsgBox "Your Invoice was successfully Saved"
 
I use: if FileExists("c:\myfile.xls") then

Code:
Public Function FileExists(ByVal pvFile) As Boolean
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
FileExists = fso.FileExists(pvFile)
Set fso = Nothing
End Function
 
Thanks Ranman, I'll give it a try and let you know how i get on.

Regards

EasygoingDave
 

Users who are viewing this thread

Back
Top Bottom