Results 1 to 10 of 10
  1. #1
    kirky is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    43

    Button in subform detail to pop windows explorer focusing to folder name identical to DocumentNo


    Dear Experts,

    Good day!

    Could you please help me modify this code to fit the needs for my db.
    I have a screenshot attached herein and the code I found in a forum.

    Thank you!

    Code:
    Dim Foldername As String
    Foldername = "\\106.154.208.11\Data\"
    Shell "C:\WINDOWS\explorer.exe """ & Foldername & "", vbNormalFocus
    Attached Thumbnails Attached Thumbnails PopupfolderbasedonDocNo.jpg  

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Its not clear what your question is
    The code correctly opens a named folder

    Don't assume we have a detailed knowledge of your database even if you have posted previous questions related to it

    If you want it to find a folder depending on the record selected then you could use a DLookup.
    Something like

    Code:
    Foldername = DLookup("FolderPath","TableName","ID = " & Me.ID)
    Note that you may need to remove trailing backslashes to get such code to work

    Code:
    Foldername = DLookup("FolderPath","TableName","ID = " & Me.ID)
    If Right(FolderName,1)="\" Then FolderName=Left(FolderName,Len(FolderName)-1)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

    I apologizes for the short detail of my db, actually the screenshot ive posted has an unbound mainform and a subform bound to table.
    I had a button at the right side where i and the user will click to pop up the windows explorer based on the field "DocumentNo" in a subform.
    So, in every DocumentNo in the subform detail corresponds also a folder named by a DocumentNo.

    I do hope i was able to make it clear my point sir Ridders52 and i am sorry for it.

    Thank you and have a nice day!

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    So can you adapt what I wrote to get this working?
    Clearly it won't work if DocumentNo = 'Later'

    If your command button is in the main form, then you will need to reference the controls in the subform
    Allen Browne explains how to do that at: http://allenbrowne.com/casu-04.html
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

    Good day!

    Sorry for the late reply and thank you for your guidance. Anyway, let me rephrase the result i want to happen in my db.

    Mainform Name = Design Manual (unbound)
    Subform Name = SubPMSection1 (bound to tblPMSection1)
    FolderName Path= S:\Final Document for Project\Part 2. Procurement Manual\Section 1_Mechanical\Subsection 1-1_GT, GTG & ST, STG_Siemens AG


    "Folder Structure and Naming"

    Final Document for Project
    Part 2. Procurement Manual
    Section 1_Mechanical
    Subsection 1-1_GT, GTG & ST, STG_Siemens AG
    SEC_QFD-M-001


    1) What the user want to happen is when they click the "folder icon" in each record that has a corresponding DocumentNo it will locate and pop up that folder.
    The folder name is identical to the DocumentNo listed in subform shown in the screenshot. Never mind the Later word in the DocumentNo because it will be replace later on once finalized.

    2) The magnifying glass icon also is, when the user click, it will pop up the pdf file based as well to the DocumentNo


    The second part was already done and its working.


    I hope you can help me for the first part sir Ridders52.

    Please see the screenshot updates
    Attached Thumbnails Attached Thumbnails PopupfolderbasedonDocNo.jpg  

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    I'm not clear what the issue is.
    The original code will open a named folder
    You just need to create a string as I suggested in post 2 which contains all parts of the folder path
    You can either save that in a table or concatenate the different parts.

    Having said that, it's possible Access will have problems with the full stops and commas in the folder path.
    It will definitely object if you include an apostrophe.

    What confuses me is that your other button opens the actual file successfully so you have the full file pat already.
    I do have functions to extract the folder name (or file name) from a complete file path. Would you like me to upload either of these?
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

    This is the code that ive been using for getting the file.
    I want the folder icon in my screenshot to work for another routine which is to pop up the sub folder matching the DocumentNo

    Here is the code im using for popping up the pdf file.

    Code:
    Private Sub cmdOpenPDF_Click()
       
    Dim colFiles As New Collection
    Dim direc As String
    Dim filetosearch As String
    filetosearch = Me.No & "_" & Me.DocumentNo & "_" & Me.RevisionNo & ".pdf"
    
    'you may need to add & ".pdf" onto the filetosearch line if the combobox doesn't have .pdf in it
    
    
    direc = Nz(DLookup("PDFsFolder", "tblPDF", "PdfId = 20"), "")
    RecursiveDir colFiles, direc, filetosearch, True
    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
    MsgBox ("Open PDF file for " & No & "_" & DocumentNo & "_" & RevisionNo & "?")
    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

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Have a look at the database I uploaded in this thread
    https://www.access-programmers.co.uk...d.php?t=299228
    It includes code to open explorer at a specific folder containing a selected file.
    It opens explorer in a web browser control in Access but is otherwise similar to what you want
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

    I cannot download the db file attached in the post you've given.
    May I ask from you sir if possible the last code im posted can be modified like this routine

    When they click the magnifying glass icon, if the DocumentNo match to pdf file, the pdf file will pop up, if not, then pop up the subfolder match to DocumentNo

    Could it be possible sir Ridder52 basing the last code ive posted?

    I am very sorry i only have a little understanding the vba code.

    Thank you!

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    OK I'll attach the example db here....
    The only part relevant to you is opening explorer at a specified folder
    Attached Files Attached Files
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 04-10-2018, 08:55 AM
  2. Replies: 4
    Last Post: 03-09-2017, 04:08 PM
  3. Replies: 9
    Last Post: 12-08-2016, 01:30 PM
  4. Replies: 9
    Last Post: 10-30-2014, 12:31 PM
  5. Create Windows Folder Regime (Many Sub Folders)
    By MSDeveloper in forum Code Repository
    Replies: 1
    Last Post: 10-14-2012, 01:43 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