Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    dniezby is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2013
    Posts
    183

    Question Image from Textfield Link?

    I want the user to enter a URL that points to an image URL. (EG: http://myphoto.com/image.gif) but on my form, I want it to show the actual image. Is this possible? I had initially tried this with a browser control and it worked wonderfully however it doesn't work for the way I want to present the data. I want to present it with a list of images and the name. Think a list of football (soccer) Teams with the name in one column and their logo in the next. But the logo loads from the URL. Rather than embed each image.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    51,728
    Image control has a ControlSource property. ControlSource can be bound to Attachment field or text field or an expression. Latter two must be a file path, not a web link. So have to download image.

    https://stackoverflow.com/questions/...-image-control

    https://stackoverflow.com/questions/...ure%20control.
    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.

  3. #3
    dniezby is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2013
    Posts
    183
    Hmm...I just found an article which says it can be done. It says I need to write a small function. This is the function it says I should create though I don't think I've ever written a function. Where would I put that code? Here is the code they wrote.

    Code:
    Public Function UrlContent( _    ByVal Id As Long, _
        ByVal Url As String, _
        Optional ByVal Folder As String) _
        As Variant
    
    
        Const NoError   As Long = 0
        Const Dot       As String = "."
        Const BackSlash As String = "\"
       
        Dim Address     As String
        Dim Ext         As String
        Dim Path        As String
        Dim Result      As String
       
        ' Strip leading and trailing octothorpes from URL string.
        Address = HyperlinkPart(Url, acAddress)
        ' If Address is a zero-length string, Url was not wrapped in octothorpes.
        If Address = "" Then
            ' Use Url as is.
            Address = Url
        End If
       
        If Folder = "" Then
            ' Import to IE cache.
            Result = DownloadCacheFile(Address)
        Else
            If Right(Folder, 1) <> BackSlash Then
                ' Append a backslash.
                Folder = Folder & BackSlash
            End If
       
            ' Retrieve extension of file name.
            Ext = StrReverse(Split(StrReverse(Address), Dot)(0))
            ' Build full path for downloaded file.
            Path = Folder & CStr(Id) & Dot & Ext
           
            If DownloadFile(Address, Path) = NoError Then
                Result = Path
            End If
        End If
       
        UrlContent = Result
       
    End Function
    Then is seems all I need to do is add this to the form?
    Code:
    Select *, UrlContent(0, [Url]) As Path From SomeTable;
    Last edited by dniezby; 01-24-2023 at 05:46 PM. Reason: Fixed code formatting.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    51,728
    Right, that function downloads picture to a folder and returns that folder path. Function is called in form's RecordSource query. Bind Image Control to the calculated Path field. Or call function directly from ControlSource property.

    Clearly stated in function comments: "' Download (picture) file from a URL of a hyperlink field to a' (temporary) folder, and return the full path to the downloaded file'' This can be used as the control source for a bound picture control."

    Basically, same approach presented in the two links I posted.

    Function could go in a general module.

    Please make sure code is posted with proper formatting so it can be easily read.
    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.

  5. #5
    dniezby is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2013
    Posts
    183
    Quote Originally Posted by June7 View Post
    Right, that function downloads picture to a folder, saves that path to a text field named URL then calls function in form's RecordSource.

    Basically, same approach presented in the two links I posted.

    Please make sure code is posted with proper formatting so it can be easily read.
    Yeah, I did that. For some reason the code posted like that. It was strange. I tried to fix it but it still came through strange...Oh wait...Let me try something. I'll fix it so that it's easier for the next person to read.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    11,576
    Yikes, that code post is yucky. I took a shot at indenting it for anyone who cares. It may not be 100% correct:
    Code:
    'Download (picture) file from a URL of a hyperlink field to a' (temporary) folder, and return the full path to the downloaded file.
    'This can be used as the control source for a bound picture control. If no Folder is specified, the user's IE cache folder is used.
    'Typical usage in the RecordSource for a form or report where Id is the unique ID and Url is the hyperlink field holding the URL to
    'the picture file to be displayed:  - to a cached file where parameter Id is not used:
    
    'Select *, UrlContent(0, [Url]) As Path From SomeTable;
    ' - or, where Id is used to create the local file name:
    
    ' Select *, UrlContent([Id], [Url], "d:\somefolder") As Path From SomeTable;
    ' Then, set ControlSource of the bound picture control to:
    ' Path 2017-05-28. Gustav Brock, Cactus Data ApS, CPH.
    
    Public Function UrlContent(ByVal Id As Long, ByVal Url As String, Optional ByVal Folder As String) As Variant
    
    Const NoError As Long = 0
    Const Dot As String = "."
    Const BackSlash As String = "\"
    Dim Address As String, Ext  As String, Path As String, Result As String
    
    'Strip leading and trailing octothorpes from URL string.
    Address = HyperlinkPart(Url, acAddress)
    
    'If Address is a zero-length string, Url was not wrapped in octothorpes.
    If Address = "" Then  ' Use Url as is.
         Address = Url
    End If
    
    If Folder = "" Then
         ' Import to IE cache.
         Result = DownloadCacheFile(Address)
    Else
         If Right(Folder, 1) <> BackSlash Then
              ' Append a backslash.
              Folder = Folder & BackSlash
         End If
         
    'Retrieve extension of file name.
         Ext = StrReverse(Split(StrReverse(Address), Dot)(0))
         ' Build full path for downloaded file.
         Path = Folder & CStr(Id) & Dot & Ext
         If DownloadFile(Address, Path) = NoError Then
              Result = Path
         End If
    End If
    
    UrlContent = Result
    
    End Function
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    dniezby is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2013
    Posts
    183
    Okay, code fixed...I've never written a function before. Where does one put this in the file? Do I just open the VBA editor and just paste this code? Or do I have to select specific locations?

  8. #8
    dniezby is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2013
    Posts
    183
    LOL, Looks like we were both fixing the code layout at the same time. It was fixed in the original posting.

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    51,728
    You read my second post before I edited so the quote is not what I finally posted. Regardless, my original comment still applies: file must be downloaded.

    Open VBA editor, insert a new module, paste your code. Don't name module same as procedure.
    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.

  10. #10
    dniezby is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2013
    Posts
    183
    Thanks for all your help. It is really appreciated. I've upvoted your reputation if that helps as well.

    Okay, so I've placed that code in a general module. I named the module - DLPictureModeul

    For my practice table I have three fields. ID (DUH), TeamName,TeamLogo(Which is a URL to the image from their official sites),TeamWebsite

    In the code I've shown, do I change anything to reflect these field names?

    And the code that is supposed to go on the form, do I put that into an OnLoad Event of the form?

    Thanks again in advance. I can't tell you how much I've learned already from users like you.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    51,728
    No event, just query or Image control.

    Query:
    SELECT table.*, URLContent([ID], [TeamLogo], "C:\MyFolderPathToSaveImage") AS Path FROM table;

    Image control:
    =URLContent([ID], [TeamLogo], "C:\MyFolderPathToSaveImage")

    This function calls two other functions: DownloadCacheFile and DownloadFile. Must get those functions as well - paste into same module.

    Could you provide link for where you found this code?

    Did you misspell DLPictureModeul?
    Last edited by June7; 01-25-2023 at 12:43 PM.
    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.

  12. #12
    dniezby is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2013
    Posts
    183
    Could you provide link for where you found this code?


    Here is where I got the code



    Did you misspell DLPictureModeul?
    LOL, I did.


    Okay, let me see if I can get this working. I'll be back.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    51,728
    Need to also get the code for DownloadCacheFile and DownloadFile functions from that same article. Paste into same module.

    As well as the API functions at the top.

    Every module should have Option Explicit at top.

    Review http://fmsinc.com/MicrosoftAccess/mo...20be%20Checked
    Last edited by June7; 01-25-2023 at 12:44 PM.
    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.

  14. #14
    dniezby is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Apr 2013
    Posts
    183
    ARRGGH

    Why is something that should be so simple so difficult?! I wish I could find a copy of that sample database so I can see what he did to make it work.

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    51,728
    It's there. Link is at end of article under "Further Reading":

    Full code (running in both 32- and 64-bit version of Access) and samples of both reports, a normal form, and a continuous form is attached for Access 365: PictureUrl.zip
    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.

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

Similar Threads

  1. Replies: 5
    Last Post: 01-19-2023, 01:11 PM
  2. Add a url link to an image on a form
    By mlove in forum Programming
    Replies: 4
    Last Post: 08-14-2017, 11:13 AM
  3. Cannot show the link image steadily
    By pencheng in forum Access
    Replies: 4
    Last Post: 07-18-2016, 03:15 AM
  4. subform image link
    By anchamal in forum Forms
    Replies: 3
    Last Post: 01-15-2014, 12:35 AM
  5. Link vs. imbed image: result is counterintuitive
    By VirgilMachine in forum Access
    Replies: 14
    Last Post: 12-13-2011, 01:55 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