Results 1 to 8 of 8
  1. #1
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273

    Open pictures in folder.

    Hello,



    I have a button on a form to open pictures, using the following code...

    Code:
      Application.FollowHyperlink "T:\Collective Reporting\Accident Folders\" & strFYear & "\" & Me.[NRptNo] & "\01.JPG"
    This works great if I only want to open the picture named 01.
    Is there a way I can open this first picture, and be able to scroll through the rest of the pictures that are in that same folder? It used to work with the old photo viewer, but now we are using Photo Gallery, and it won't bring up the scroll arrow.

    Thank you.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Review this link and examples. And this one.

    You may find more examples using Google or searching within the forum.

    Also, depending on your vba skills, you could use some variables within your code and some logic to allow for file type and/or folder name. This would be in addition to and similar to your use of strFYear.
    How do you currently supply values to strFYear?

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I'm guessing that the notion of using file dialog object is to multi select?
    Sounds like the viewer app needs to load each image you want to view so maybe the fd along with code using Dir function. Or a form button to open the next image from a list or a table of records, assuming the paths are table records.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273
    I'm not completely getting it. The code in the example seems to be working to open the browser window, but when I select a folder, or path directly to the folder, it says there is nothing to show, ie no pictures in the folder.
    I believe Micron is onto something where the code doesn't specify it is looking for a JPG, or anything about Photo Gallery. And I don't know how to write that part, or where it would go.
    Here is the code I have so far...

    Code:
    Private Sub ComPic_Click()On Error GoTo ProcError
     Dim strYear As String
     Dim strFYear As String
     Dim sFolder As String
     
     If Me.txtNMonth < 4 Then
        strYear = Me.txtNYear - 1
     Else: strYear = Me.txtNYear
     End If
        
     strFYear = Right(strYear, 2)
     strFYear = "FY" & strFYear
     
        ' Open the select folder prompt
        With Application.FileDialog(msoFileDialogFolderPicker)
            .InitialFileName = "T:\Collective Reporting\Accident Folders\" & strFYear & "\" & Me.[NRptNo]
            If .Show = -1 Then ' if OK is pressed
                sFolder = .SelectedItems(1)
            End If
        End With
        
        If sFolder <> "" Then ' if a file was chosen
            ' *********************
            ' put your code in here
            ' *********************
        End If
     
     
     
    
    
    ExitProc:
        Exit Sub
    ProcError:
        Select Case Err.Number
            Case 490
             MsgBox "No Pictures Available"
            Case Else
                MsgBox Err.Number & ": " & Err.Description, vbCritical, _
                           "Error in cmdOK_Click Event Procedure..."
        End Select
        Resume ExitProc
    End Sub

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    So need to loop through image files in folder and display in viewer. Since viewer doesn't offer 'Next' and 'Previous' navigation of images, this means opening image, viewing, closing, returning to Access, selecting next file. Annoying. Consider:

    Code:
    Sub ViewImages(ByVal strFolder As String, strFileSpec As String)
        Dim strTemp As String
        Dim vFolderName As Variant
        strFolder = TrailingSlash(strFolder)
        strTemp = Dir(strFolder & strFileSpec)
        Do While strTemp <> vbNullString
            FollowHyperlink strFolder & strTemp
            If MsgBox("Continue?", vbYesNo) = vbYes Then
                strTemp = Dir
            Else
                Exit Do
            End If
        Loop
    End Sub
    Call that code like: ViewImages "C:\Users\Owner\June\MyStuff", "*.jpg"

    Could load image file names from folder to a listbox and user clicks through listbox. http://allenbrowne.com/ser-59.html

    Or view images on form with Image control where you can do navigation.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    You are using FolderPicker?

    You should be using FilePicker surely?

    https://docs.microsoft.com/en-us/off...ion.filedialog
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    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

  8. #8
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273
    I've never used this code before, so I never would have caught it. But Welshgasman was right on. Changing FolderPicker to FilePicker did the trick. It doesn't open the picture, but opens the correct folder to the pictures, and when opened, I can scroll through the pictures in that folder again. This may be a better option, since other users may have a different picture viewing program that they use.
    Thank you all for your help.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-13-2015, 10:21 AM
  2. Replies: 10
    Last Post: 09-09-2015, 03:25 AM
  3. open folder/Make new folder(example)-VBA Code
    By Madmax in forum Code Repository
    Replies: 3
    Last Post: 03-13-2012, 09:17 AM
  4. Replies: 11
    Last Post: 10-01-2010, 11:12 PM
  5. Enter a folder name and open that folder
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 09-05-2010, 04:39 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