Results 1 to 7 of 7
  1. #1
    Cookie is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    45

    No image in image box when control source is hyperlinked to image in a folder.

    MS Access Office 365

    Part of the cat rescue organisation database I am working on has a form with a picture box. The picture box is supposed to show the image hyperlinked in the PhotLink field; i.e. the photo of the cat. The field is visible on the form so you can click on the hyperlink and get the bigger picture. That works ok but if you are flicking through the records, this slows the process down a lot.

    The file path to the picture is put into the Photolink field by executing a procedure when a button (Get Photo Link) is clicked on with the mouse. The control source for the image is the PhotoLink field. Not sure if Get Focus comes into play here.

    The adapted procedure below (thanks to others) performs this function, but I do not know why the image is not automatically placed in the picture box.

    Private Sub Command317_Click()
    'First, set a Reference to the Microsoft Office XX.X Object Library

    Dim strButtonCaption As String, strDialogTitle As String
    Dim strHyperlinkFile As String
    Const msoFileDialogFilePicker As Long = 3
    Dim FD As Object
    Dim file As Variant
    Set FD = Application.FileDialog(msoFileDialogFilePicker)
    strButtonCaption = "Save Hyperlink"
    strDialogTitle = "Select File to Create Hyperlink to Photo Link"
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
    .Filters.Clear
    .Filters.Add "All Files", "*.*"


    .AllowMultiSelect = False
    .FilterIndex = 1 'Database files
    .ButtonName = strButtonCaption
    .Title = strDialogTitle
    If .Show Then
    For Each varItem In .SelectedItems 'There will only be 1
    'Extract Caption and and add Address of Hyperlink (Caption#Address)
    strHyperlinkFile = Mid$(varItem, InStrRev(varItem, "") + 1) & "#" & varItem
    Me![PhotoLink] = strHyperlinkFile
    Next varItem
    End If
    End With
    End Sub

    I think maybe by using the button to fill the PhoLink box I haven't told the picture box that something is in there. The format of the PhotoLink field is as hyperlink.


    Can I have some help with this please?


    Thanks.

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    As you are probably aware most developers avoid using attachment fields due to bloat.

    Store your cat pictures in a seperate folder and store the path to that picture in your table.

    attached is a small sample which may help you. It includes a folder for pictures with a default "No Image" pic.
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    Cookie is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    45
    Thank you Moke123,

    That DB you put together for me helped a lot. I've got that working in the main project with a slight modification to enable the user to pick an image from another file location.

    I noticed the PicPath field is not clickable though. When I set it as a hyperlink it resulted in a Compile Error. It would be good if it was clickable as a hyperlink because then the user can get the bigger picture.
    Last edited by Cookie; 09-18-2020 at 09:40 AM. Reason: Typo "and" was meant to be "an"

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    I never use hyperlink datatype. It is too much of a pain in the @$$ to work with. Use text datatype and a double click event on the control with
    Code:
    Private Sub PicPath_DblClick(Cancel As Integer)
    
    
    If IsNull(Me.PicPath) Then Exit Sub
    
    
    Application.FollowHyperlink Me.PicPath
    
    
    End Sub
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    Cookie is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    45
    Thank you Moke 123,

    I must give credit to developers who see the pros and cons of using the tools that are there to use in novel ways and in some cases save novices from imminent peril. Many of us are time poor or not working proactively with the applications everyday so, you know, we have to crawl before we can walk. This project (the Cat Rescue DB was started out of a COVID-19 Lockdown. I am sure many are in the same situation - do something to get your mind of the pandemic.

    OK, the Private sub you gave me did the trick. Before you showed me that, I didn't quite understand I had to use the line
    Application.FollowHyperlink Me.PicPath

    So far so good.

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Happy to help Cookie.

    You'll see over time that there are many ways to do the same things with vba. You'll wind up going back and re-doing parts of your database and just when you think you have it just right you'll learn something new and its back to the drawing board. Along the way you'll come across things that intrique you but you just cant seem to get it to work. Then months or more later you'll have an "Aha!" moment and that difficult concept will all of a sudden seem easy and you will wonder why it seemed so hard before. It happens to us all. I'd bet that you've already experienced that since your initial insistance on using send keys a while back.

    When you have some time I'd suggest you take a look at this procedure . . . http://access.mvps.org/access/api/api0018.htm
    You can use it in place of Application.FollowHyperlink. It may look a little intimidating but it is a procedure you will probably use in this and any future projects.
    It will launch any file with the default program on your computer. A photo gets opened with your default photo viewer. A url is opened in your default browser. An email address is opened in your mail program. Its a very versatile piece of code.

    Another one of my favorites is Albert Kallal's Super Easy Word Merge . . .https://hitechcoach.com/downloads-ma...asy-word-merge
    You can basically just import it into your project and it just works.
    It may be useful should there be paperwork that needs to be generated for Cat adoptions.

    Best of luck with your project!
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    Cookie is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Posts
    45
    Thank you moke123,

    I've copied that link to my desktop to follow up on.

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

Similar Threads

  1. Replies: 5
    Last Post: 07-10-2020, 12:41 PM
  2. Replies: 10
    Last Post: 02-25-2019, 07:36 PM
  3. Replies: 2
    Last Post: 03-14-2018, 11:10 AM
  4. Replies: 1
    Last Post: 12-26-2016, 08:57 AM
  5. Replies: 3
    Last Post: 07-13-2015, 12:07 PM

Tags for this Thread

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