Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need tweaking of code open a pdf file

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
0
36
US
I have a folder with 167 pdf files named with a persons name.
such as some of the follwing:
Adthes, Dani HandWritten.pdf
or
Athur, Kater - FFT - 7-29-11.pdf
the names are Adthes, Dani and Athur, Kater
The table has the names but not the extra stuff in the file name. I don't want to edit every file name.

currently my code does not open anything.
the code however finds 1 document since the code .FoundFiles.Count has a 1 in it when I pause it and hold my mouse over the coding.
Code:
    Dim FiletoOpen, StudentName, FullPath As String
    StudentName = Me.Childs_Last_Name & ", " & Me.Childs_First_Name
    FullPath = "S:\Student Fee Folder\returned E-forms from parents\Original files\"
    FiletoOpen = FullPath & StudentName & "*" & ".pdf"
    
    With Application.FileSearch
        .NewSearch
        .LookIn = FullPath
        .FileName = StudentName & "*" & ".pdf"
        If .Execute(SortBy:=msoSortByLastModified, SortOrder:=msoSortOrderDescending) > 0 Then
            If .FoundFiles.Count > 1 Then
                'launch Windows Explorer
                RetVal = ShellExecute(hwnd, "open", BrowserExec, FullPath, Dummy, SW_SHOWNORMAL)
            Else
                'just open the file
                RetVal = ShellExecute(hwnd, "open", FiletoOpen, "", FullPath, SW_SHOWNORMAL)
            End If
        Else
            MsgBox FileName, vbInformation, "File Not found"
            RetVal = ShellExecute(hwnd, "open", BrowserExec, FullPath, Dummy, SW_SHOWNORMAL)

        End If

Since it found 1 pdf file, is there anyway to extract the file name that I can pass that to the ShellExecute. Sicne it seems Adthes, Dani*.pdf will not open?

Or any other ideas how to make this work?
I eventually need to email each person their exact pdf with their name to their email address in the table. So I want to automate this as much as possible.

TIA

DougP
 
Hi DougP,
Some time ago I set up something that performed a simular function and found trouble in maintaining the links due to adding and changing files. I then was directed to Allan Brownes module "List files to tables" at his site It was a little work to set up at first but I never had to look back. Well worth the time.
 
You could use Dir(FullPath & StudentName & "*" & ".pdf") to get the first match, then user Dir() with no param to get successive files for this student.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top