Renaming files now obviously stops code working

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,570
Office Version
2007
Platform
Windows
Hi,
I have this code in use which when in my database & i press its button the corresponding invoice is then shown.
At the time the invoice were saved like this,
1.pdf
2.pdf
3.pdf
Code:
Private Sub OpenInvoice_Click()

    Const FILE_PATH As String = "C:\Users\Ian\Desktop\REMOTES ETC\DR COPY INVOICES\"
    
    If txtInvoiceNumber = "N/A" Or Len(txtInvoiceNumber) = 0 Then
                MsgBox "Invoice N/A For This Customer", vbExclamation, "N/A INVOICE NOTICE"
    Else
        If Len(Dir(FILE_PATH & txtInvoiceNumber.Value & ".pdf")) = 0 Then
            If MsgBox("Would You Like To Open The Folder ?", vbCritical + vbYesNo, "Warning Invoice is Missing.") = vbYes Then
                CreateObject("Shell.Application").Open ("C:\Users\Ian\Desktop\REMOTES ETC\DR COPY INVOICES\")
            End If
        Else
            CreateObject("Shell.Application").Open (FILE_PATH & txtInvoiceNumber.Value & ".pdf")
        End If
    End If
End Sub
I have just had to rename all the invoices so now see below
1.pdf becomes 1_04_03_2015.pdf
2.pdf becomes 2_07_03_2015.pdf
3.pdf becomes 3_02_04_2015.pdf

So the invoice number is now saved with the date it was created afterwards.

Because of this i now see the msgbox pop up saying Warning invoice is missing,would you like to open the folder.

My question is how can i fix this if the date will be different for each invoice.

Thanks
 

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,102
Office Version
365
Platform
Windows
Use "*.pdf" rather than ".pdf" and see if that works.
 

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,102
Office Version
365
Platform
Windows
You will need to use the Dir command to get the string then pass it to the shell if you want to do it that way. The shell i dont think will like wildcards.
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,570
Office Version
2007
Platform
Windows
Hi,
I have tried the new code as mentioned in post #2 but not i dont even see the msgbox pop up.
With regards post #3 what / or how do i go about that
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,545
Messages
5,511,958
Members
408,871
Latest member
Usman21

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top