Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Open an explorer search window via a link from a form

Posted on 2011-10-31
22
Medium Priority
?
287 Views
Last Modified: 2012-06-27
I have a form that is used for customer sales details.  We sometimes scan in papers and save the scanned image (PDF) with a file name based on their name.

I was trying to find a way to put a button on a form so that when the user pressess the button  a windows explorer window opens filtered with only the images under the patients name listed AND have the form have a drop down list with links each image saved for that customer for the user to select.
Customer: John Smith
Test image file name: 39_Smith_John_2011-1012_3DS123.pdf

Are both scenarios possible?

Thank you.
0
Comment
Question by:thandel
  • 11
  • 7
  • 4
22 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37058449
what is the path where you are saving the images ?

you can try this in the click event of the button

dim folderPath="C:\MyImages\PatientName"

followhyperlink  folderPath
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37058452
what is the path where you are saving the images ?

you can try this in the click event of the button

dim folderPath as string

 folderPath="C:\MyImages\PatientName"

followhyperlink  folderPath
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 37058490
Have you looked at this API call for opening the File Open/Save dialog?

With this call you should be able to do something like:

strFilter = ahtAddFilterItem(strFilter, "John Smith (*Smith_John*.*", "*Smith_John*.*"))
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:thandel
ID: 37059799
Is the API calling a Save As Dialog?  I don't want any dialogs just to open a window with the various PDFs and then the use can select  as well as popular a drop down list that the user can select from.
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 37060321
Yes,

The API calls the Open/Save dialog, but you can set the parameters for Open or Save, you can also pass it a directory to search in, so what you will see, when configured properly is the File Open dialog, with all of the Smith_John files listed for selection.
0
 

Author Comment

by:thandel
ID: 37070185
Fyed I'm having trouble understanding how to implement this code.  

capricorn1 this is good to open a folder but I was hoping to open the folder filtered based on data on the form (customer first and last name)
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37070226
thandel,

give more info   <what is the path where you are saving the images ? > post it here..

so we can see how the path relates to ----  < to open the folder filtered based on data on the form (customer first and last name) >
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 37070688
Take a look at the attached file for how to implement this search.

What you do with the file name, after you select it is up to you.

OpenFile.mdb
0
 

Author Comment

by:thandel
ID: 37071988
capricorn1: Path is \\mv\drs
0
 

Author Comment

by:thandel
ID: 37072015
Thanks Fyed, that works OK but can I pull a vaiable somehow to use with followhyperlink  folderPath
so the user can open a file?
0
 

Author Comment

by:thandel
ID: 37072019
...also use that variable to populate a combo box?  Now that would be really cool.
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 37072081

You could use the Dir() function to step through all of the files in a folder and identify those that meet the needs.

Copy this subroutine as a replacement for the current click event, and see if it is what you are looking for.
Private Sub cmd_Search_Click()
    
    Dim strFilter As String
    Dim strPath As String
    Dim lngFlags As Long
    
    lngFlags = ahtOFN_FILEMUSTEXIST Or ahtOFN_HIDEREADONLY Or ahtOFN_NOCHANGEDIR
    
    If Len(Me.txt_Path & "") = 0 Then
        MsgBox "Enter a valid path to find the file(s) in:"
        Me.txt_Path.SetFocus
        Exit Sub
    End If
    
    strPath = Me.txt_Path
    If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
    If Len(Dir(strPath & "*.*")) = 0 Then
        MsgBox "There are no files in the entered path or the path does not exist!"
        Me.txt_Path.SetFocus
        Exit Sub
    End If
    
    If Len(Me.txt_SearchFor & "") = 0 Then
        strFilter = ahtAddFilterItem(strFilter, "All files (*.*)", "*.*")
    ElseIf Me.cbo_Search_How = "Begins with" Then
        strFilter = ahtAddFilterItem(strFilter, Me.txt_SearchFor & " (" & Me.txt_SearchFor & "*.*)", Me.txt_SearchFor & "*.*")
    ElseIf Me.cbo_Search_How = "Contains" Then
        strFilter = ahtAddFilterItem(strFilter, Me.txt_SearchFor & " (*" & Me.txt_SearchFor & "*.*)", "*" & Me.txt_SearchFor & "*.*")
    End If
    
    Dim strFileName As String
    strFileName = ahtCommonFileOpenSave(InitialDir:=strPath, _
                                 Filter:=strFilter, _
                                 FilterIndex:=3, _
                                 flags:=lngFlags, _
                                 OpenFile:=True, _
                                 DialogTitle:="Hello! Open Me!")
    If Len(strFileName) > 0 Then Application.FollowHyperlink strFileName
    
End Sub

Open in new window

0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 37072107
Sorry, two trains of thought on that last message.

1.  You could create a loop and use the Dir() function to loop through all of the files in a folder, determine whether they meet your naming criteria, and if so, add them to the RowSource of a combo box.  Not too difficult, search EE for "Folder loop dir()", I'm sure you will find some code for that method.

2.  Use the API and my new code above, which uses application.followhyperlink strFileName to open the selected file.
0
 

Author Comment

by:thandel
ID: 37072170
Got it working with:

FollowHyperlink ahtCommonFileOpenSave(InitialDir:=strPath, _
                                 Filter:=strFilter, _
                                 FilterIndex:=3, _
                                 flags:=lngFlags)

Is that what you had in mind for the followhyperlink?
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 800 total points
ID: 37072235

followhyperlink "\\mv\drs"

0
 

Author Comment

by:thandel
ID: 37072252
For the looping through the files I found this but can't see how to work with a single directory and loop through the files:

    Dim file As String
    Dim folder As String
    Dim startPath As String
   
    startPath = "\\mv\drs"
    file = Dir(startPath, vbDirectory)
    While file <> ""
        If file <> "dickerman*.pdf" Then
            folder = startPath & file
            If (GetAttr(folder) And vbDirectory) = vbDirectory Then
                ' do something with 'folder'...
                Debug.Print folder
            End If
        End If
        file = Dir
    Wend
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 37072343
thandel, you wrote:

Got it working with:

FollowHyperlink ahtCommonFileOpenSave(InitialDir:=strPath, _
                                 Filter:=strFilter, _
                                 FilterIndex:=3, _
                                 flags:=lngFlags)

Is that what you had in mind for the followhyperlink?

No, but close.  If you look at my code, you will see that I created a strFileName, and set it equal to the function ahtCommonFileOpenSave(...).

I then test to make sure you didn't hit cancel in the dialog box by checking to see whether the length of strFileName = 0.
0
 

Author Comment

by:thandel
ID: 37072419
I tried followhyperlink strfilename but that didn't work as strfilename was not defined.
0
 

Author Comment

by:thandel
ID: 37072469
Opps sorry I see I had some old code, now I have your variable working.
0
 

Author Comment

by:thandel
ID: 37072474
Still having trouble with looping through so I can populate a combo box.  Can you elaborate on the looping and checking implementation?
0
 
LVL 49

Accepted Solution

by:
Dale Fye earned 1200 total points
ID: 37073025
take a look at the attached  OpenFile.mdb
0
 

Author Comment

by:thandel
ID: 37073255
OMG!  You da man!  Thanks!   I am going to split up point as I believe I got assistance from both.  Thanks so much!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question