Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195

    Converting Photo Upload Into Hyperlink

    Hi Guy's, is there a method of converting specific text from a text box into a hyperlink so i can open an image by clicking on it ?

    Here is a small image of the files in the text box

    There can be 1 to 6 images, we need to determine how many are uploaded

    I guess converting instr after Photo Upload Number ?

    Could you guy's give me an example of how i could achieve this ?

    "Photo Upload 1: Open File " https etc
    "Photo Upload 2: Open File " https etc
    "Photo Upload 3


    "Photo Upload 4
    "Photo Upload 5
    "Photo Upload 6

    In this instance there is 2 images i want to click on

    Photo Upload 1: Open File <https://image-res-platform.s3.amazon...9B8-44F4-9C47-REMOVED IMAGE NUMBER ON HERE.jpeg>
    Photo Upload 2: Open File <https://image-res-platform.s3.amazon...82D-4332-9EA8-REMOVED IMAGE NUMBER ON HERE.jpeg>

    There can be 6 images so find if 1 then convert after Photo Upload 1: Open File , if 2 if then convert after Photo Upload 1: Open File and Photo Upload 2: Open File

    etc....

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    no need for a hyperlink,
    Paste this code into a module, and it will open ANY file in its native application.
    In a form put the field and a button to open it.


    user selects a record in the list,
    click the button
    usage: OpenNativeApp txtBox




    paste this code into a module
    Code:
    'Attribute VB_Name = "modNativeApp"
    'Option Compare Database
    Option Explicit
    
    
    #If VBA7 Then
      Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As LongPtr
      Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As LongPtr
    #Else
      Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
      Private Declare Function GetDesktopWindow Lib "user32" () As Long
    #End If
    
    
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    
    
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    
    
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    
    
    
    
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    
    
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function

  3. #3
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Wow thank you ranman

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,991
    Application.FollowHyperlink "Full path to file here" e.g. Application.FollowHyperlink "https://isladogs.co.uk/access-error-codes/images/img1.png"
    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
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi ranman, these 2 lines are coming up in red?

    Code:
    #If VBA7 Then  Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As LongPtr
      Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As LongPtr
    #Else
      Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
      Private Declare Function GetDesktopWindow Lib "user32" () As Long #End If

  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,655
    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
      Private Declare Function GetDesktopWindow Lib "user32" () As Long #End If
    did you try putting #End If on its own line?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,991
    If using 64-bit Access, the #Else section will appear in red. Its normal behaviour.

    Whilst code like that works fine, it is far simpler to use Application.FollowHyperlink.
    No API call needed. Just one line of code
    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
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,121
    Hi Dave,
    Not sure what you actually want to do here. To open a file by clicking the path using FollowHyperlink as shown by Colin is the easiest. But if you want to convert the existing text to a functioning hyperlink then you need to read more about them. Are all 6 stored in the same text box or is each one in its own?
    https://bytes.com/topic/access/answe...ink-into-table
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  9. #9
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Vlad, yes I do use Application.FollowHyperlink as suggested by Colin, the problem i have is the 1 to 6 items are currently not a hyperlink otherwise i could just use that easy option

    Yes all 6 a stored in the same text box, so it could be something like

    Photo Upload 1: <https://image-res-platform.s3.amazonaws.com/81312b9d%2Fforms%2Fattachments%2FpgtUPKTtmqgUmJfwg nwA_IMG_20220212_103659_817.jpg>
    Photo Upload 2:
    Photo Upload 3:
    Photo Upload 4:
    Photo Upload 5:
    Photo Upload 6:

    So i am looking to have a button that will check if any data after Photo Upload 1: through to 6

    I have just quickly put this together on a command button called cmdConvertToHyperlink

    I know I maybe heading the wrong way about it but, this is the general aim.....

    Code:
    Dim str1 As String, str2 As String, str3 As String, str4 As String, str5 As String, str6 As StringDim strMailMessage As String
    Dim hypLink1 As Hyperlink, hypLink2 As Hyperlink, hypLink3 As Hyperlink, hypLink4 As Hyperlink, hypLink5 As Hyperlink, hypLink6 As Hyperlink
    
    
    strMailMessage = Me.txtMailMessage
    str1 = strMailMessage Find after "Open File 1: "
    str2 = strMailMessage Find after "Open File 2: "
    str3 = strMailMessage Find after "Open File 3: "
    str4 = strMailMessage Find after "Open File 4: "
    str5 = strMailMessage Find after "Open File 5: "
    str6 = strMailMessage Find after "Open File 6: "
    
    
    'Find If data after 1
    'Find If data after 2
    'Find If data after 3
    'Find If data after 4
    'Find If data after 5
    'Find If data after 6
    
    
    'hypLink1 = data after 1
        'Convert to hyperlink
        'If there is data, application.followhyperlink hyplink1
        
        '.etc
    If there is then how may of the 6 have got data after the number and colon, once we clarify only 4,5 and 6 has no data for example and 1, 2 and 3 have got data (images), convert every thing between < and > in 1,2 and 3

    So then they become a hyperlink to click on and view the images, i will check your link also

    Thank to you all for suggestions

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,991
    Duplicate post - deleted
    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

  11. #11
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,991
    The whole point of using Application.FollowHyperlink is that it works on file paths stored as text fields
    I suggest you store the file path for each photo as a separate record then use a listbox to display each of these
    Users click on any listbox item to display the image.

    For example:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	22 
Size:	294.1 KB 
ID:	47264

    The image is taken from one of my example apps which you may find useful: Folder Image Viewer
    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

  12. #12
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,655
    Yes all 6 a stored in the same text box,
    Why not use a listbox?

    If this is all one block of text then you may be able to use split() to get each line, and instr() to determine if there is a URL in each line.
    You can then load each into a listbox and open with followhyperlink.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,121
    I guess the question is how do you originally populate the list in the textbox. I might be easier to convert into a hyperlink at the time you add each individual links 1 through 6.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  14. #14
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Hi Guy's thanks to you all, I think I have a good start on this and perhaps if I add whats in the MsgBox To a Text box then have a button called cmdImage1, can i code cmdImage1 to follow hyperlink from txtImage1

    Perhaps i would need to set each text box (6) of them to hyperlink and use the button to follow that

    Code:
    Dim str1() As String, str2() As String, str3() As String, str4() As String, str5() As String, str6() As StringDim strMailMessage As String, img1 As String
    Dim intA As Integer
    
    
    strMailMessage = Me.txtMailMessage
    
    
    str1 = Split(strMailMessage, vbCrLf)
    For intA = 0 To UBound(str1)
    If InStr(1, str1(intA), "Photo Upload 1: Open File <") > 0 Then
    imgA = Mid(str1(intA), 27)
    End If
    Next intA
    
    
    MsgBox (imgA)
    
    
    MsgBox (imgA)
    Me.txtImage1 = imgA
    Me.cmdImage1.Visible = True

  15. #15
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thank you guy's for your help, got this working, once I tidy it up...

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

Similar Threads

  1. Converting text data to Hyperlink
    By jcc285 in forum Programming
    Replies: 14
    Last Post: 05-30-2019, 11:42 AM
  2. Replies: 1
    Last Post: 11-21-2018, 05:02 PM
  3. Converting Hyperlink field back to short text
    By gksmith5 in forum Access
    Replies: 3
    Last Post: 06-02-2018, 01:19 AM
  4. Linking a hyperlink (texbox) to a Photo
    By johnnyBQue in forum Access
    Replies: 5
    Last Post: 12-02-2014, 07:58 AM
  5. Export to excel with hyperlink converting
    By Jamy in forum Import/Export Data
    Replies: 0
    Last Post: 03-22-2010, 08:36 AM

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