Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    kirky is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    43

    Post Open pdf file in subfolders that matched in form texbox

    Good day everyone!

    I am looking for a vba code to open a pdf file in sub-folders that matched into the textbox value of my form using a button. Can anybody help me please solve my problem? I have here the code below I found in some forums and just modified a little to suit my needs. Thank you in advance for all the experts and have a nice day!

    ================================================== ==============

    Private Sub cmdgetfil_Click()
    Dim x As String

    x = Me.RfiNo
    Dim pdfPath As String


    'x for variable file name
    pdfPath = "\\106.154.208.10\qaqc\011. RFI&RRI PDF FILES" & x & ".pdf"
    Call OpenAnyFile(pdfPath)
    End Sub

    Function OpenAnyFile(strPath As String)
    Set objShell = CreateObject("Shell.Application")
    If FileThere(strPath) Then
    objShell.Open (strPath)
    Else
    MsgBox ("File not found")
    End If
    End Function

    Function FileThere(FileName As String) As Boolean
    If (Dir(FileName) = "") Then
    FileThere = False
    Else:
    FileThere = True
    End If
    End Function

    =================================================

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Are you saying the code doesn't work? If so does it produce any errors?


    Sent from my iPhone using Tapatalk

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051

    Open pdf file in subfolders that matched in form texbox

    Try putting chr(34) & "\\106......PDF" & chr(34)


    Sent from my iPhone using Tapatalk

  4. #4
    kirky is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    43
    The code actually working but i want to search pdf file in subfolders

  5. #5
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    http://www.ammara.com/access_image_f...er_search.html

    Any use?


    Sent from my iPhone using Tapatalk

  6. #6
    kirky is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    43
    Thank you so much andy49.....I will try it later....

  7. #7
    kirky is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    43
    Sir andy49, based on your link give I think it is useful but as a novice to access and vba i cant figure it out how to make it and fit it into my problem.
    I have a textbox and a button in a form. The textbox value is the same with the file name in the pdf situated in subfolders. I want the to find the pdf file matching
    the value in a textbox and open it.

    I do hope you can understand and provide me a guide into solving the problem.

    Thank you for catering my concern andy49

  8. #8
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    I'll certainly look later on. Could you zip your database up and put it on here?


    Sent from my iPhone using Tapatalk

  9. #9
    kirky is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    43
    Sir andy49,


    I cannot send to you the database because all employees has been block exporting file and it is limited only to few to have and access on it.

    Can i just give you a view of my database? I have a single form which display details of my continuous form and within that form I have a
    textbox with a value the same as the pdf files in a sub-folders. Then I made a one button where i want to open "the specific pdf file referring to the value in a textbox"

    I hope it sounds clear my view given...

    Anyway, when i reach home i will try to send the db

    Thank you andy49

  10. #10
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    On your form vba code (class) add the following (assuming cmdgetfil is the button and rfino is the name of the file on the combobox (see green notes about adding .pdf)


    Code:
    Option Explicit
    Private Sub cmdgetfil_Click()
    Dim colFiles As New Collection
    Dim direc As String
    Dim filetosearch As String
    filetosearch = Me.RfiNo
    
    'you may need to add & ".pdf" onto the filetosearch line if the combobox doesn't have .pdf in it
    
    
    direc = "\\106.154.208.10\qaqc\011. RFI&RRI PDF FILES"
    RecursiveDir colFiles, direc, filetosearch, False
    Dim vFile As Variant
    For Each vFile In colFiles
    OpenAnyFile (vFile)
    Next vFile
    'keep as false for a few tests so it only looks in your current folder
    End Sub
    
    
    Function OpenAnyFile(strPath As String)
    If FileThere(strPath) Then
    FollowHyperlink strPath
    Else
    MsgBox ("File not found")
    End If
    End Function
    Function FileThere(FileName As String) As Boolean
    If (Dir(FileName) = "") Then
    FileThere = False
    Else:
    FileThere = True
    End If
    End Function

    In a module add the following


    Code:
    Public Function RecursiveDir(colFiles As Collection, strFolder As String, strFileSpec As String, bIncludeSubfolders As Boolean)
    'Debug.Print strFolder
    Dim strTemp As String
    Dim colFolders As New Collection
    Dim vFolderName As Variant
    strFolder = TrailingSlash(strFolder)
    'Debug.Print strFolder & strFileSpec
    strTemp = Dir(strFolder & strFileSpec)
    'Debug.Print strTemp
    Do While strTemp <> vbNullString
    colFiles.Add strFolder & strTemp
    strTemp = Dir
    Loop
    If bIncludeSubfolders Then
    'Fill colFolders with list of subdirectories of strFolder
    strTemp = Dir(strFolder, vbDirectory)
    Do While strTemp <> vbNullString
    If (strTemp <> ".") And (strTemp <> "..") Then
    If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0 Then colFolders.Add strTemp
    End If
    strTemp = Dir
    Loop
     'Call RecursiveDir for each subfolder in colFolders
    For Each vFolderName In colFolders
    Call RecursiveDir(colFiles, strFolder & vFolderName, strFileSpec, True)
    Next vFolderName
    End If
    End Function
    Public Function TrailingSlash(strFolder As String) As String
    If Len(strFolder) > 0 Then
    If Right(strFolder, 1) = "\" Then
    TrailingSlash = strFolder
    Else
    TrailingSlash = strFolder & "\"
    End If
    End If
    End Function
    It works on mine opening a PDF

    Let me know if you have any questions.

  11. #11
    kirky is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    43
    I will check one sir andy49 and thank you very much for your help...
    Ill give you feedback soon.

    Thank you once again!

  12. #12
    kirky is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    43
    Sir andy,

    Good day!

    Im sorry for late feedback regarding the vba you gave me. Actually there is an error when I try to run it. Could you please help me for this....
    Please see below images what did I do wrong for it.
    Click image for larger version. 

Name:	Form.PNG 
Views:	18 
Size:	59.1 KB 
ID:	26896

    Click image for larger version. 

Name:	Capture2.PNG 
Views:	17 
Size:	113.9 KB 
ID:	26894
    Click image for larger version. 

Name:	Error.PNG 
Views:	17 
Size:	29.7 KB 
ID:	26895

    Thank you sir andy49 and have a nice day!

  13. #13
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Can you send me a screenshot of the recursivdir module please


    Sent from my iPhone using Tapatalk

  14. #14
    kirky is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    43
    Sir andy49,

    here is the module you made for me....
    thank you


    Click image for larger version. 

Name:	Capture3.JPG 
Views:	17 
Size:	102.9 KB 
ID:	26897

  15. #15
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Thx what error is it showing


    Sent from my iPhone using Tapatalk

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 09-10-2014, 01:15 PM
  2. Replies: 3
    Last Post: 08-28-2013, 11:08 PM
  3. Replies: 1
    Last Post: 06-06-2013, 06:12 PM
  4. Import multiple xls from a few subfolders
    By artec in forum Import/Export Data
    Replies: 6
    Last Post: 03-31-2012, 09:23 AM
  5. Open pdf file from Access form
    By lios1984 in forum Access
    Replies: 7
    Last Post: 02-21-2012, 01:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums