Results 1 to 14 of 14
  1. #1
    AndyRob1973 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2020
    Posts
    81

    Converting a concatenated string into a hyper link

    Hello all,



    I am trying to write a query(Access 2010) which concatenates two fields from a table to make a third field which needs to be a hyperlink that can be clicked on to take the user to a particular part of a webpage.

    eg

    COLUMN A= https://www.abc.com
    COLUMN B = 123456
    COLUMN C = [COL A]&'/'&[COL B]

    So that the output reads https://www.abc.com/123456 and can be clicked on to take you to the relevant page.

    It may be that I can do this as a calculated field in the original table?

    Thankyou

  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,651
    You can use application.followhyperlink or better yet . . . http://access.mvps.org/access/api/api0018.htm
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    AndyRob1973 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2020
    Posts
    81
    Thankyou!

    So would I type in the access query something like:

    application.followhyperlink([COL A]&'/'&[COL B])

  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,651
    You would concatenate the string in your query. In the double click event of the control on your form you would have
    Code:
    Application.FollowHyperLink Me.YourControlName
    Many experienced developers avoid the hyperlink datatype and opt to do like above.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    AndyRob1973 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2020
    Posts
    81
    Thanks moke123,

    I'll try that.

    Could a similar thing be done in the query itself ie so that when you run the query, each line has a url link?

    Or could it be done as a calculated field in the source table?

  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,651
    Quote Originally Posted by AndyRob1973 View Post
    Could a similar thing be done in the query itself ie so that when you run the query, each line has a url link?
    No. You should use a continuous form or subform to display the results of the query and set the double click event of the control to launch the URL.

    Or could it be done as a calculated field in the source table?
    Normally you would want to avoid using a calculated field in the table where the information is stored already.
    You would concatenate it in the source query for the form or report as needed.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    AndyRob1973 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2020
    Posts
    81
    I have kind of managed it seems to only take me to the home page rather than the specific page in the URL.

    (I do something similar n POWER BI dashboard and that allows me to go the specific page.

  8. #8
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    It should take you to whatever URL you have constructed.
    try adding a debug.print [COL A]&'/'&[COL B] to make sure your getting it right.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  9. #9
    AndyRob1973 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2020
    Posts
    81
    I've checked the url quite a few times. When I cut and paste what I have constructed into the internet address bar it then opens the correct page.

    I tested it in excel and the same thing happens, but in power bi it goes to the correct page! Bizarre!

  10. #10
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Check the attached sample (test the links in Form1), it works as expected.
    Attached Files Attached Files

  11. #11
    AndyRob1973 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2020
    Posts
    81
    Thankyou accesstos,

    That's a really good example for me to work with. Unfortunately when I plug in the same details for the website I want to connect to , it takes me to the home page rather than the specific page in the url.

    If I copy and paste my url into the browser it works fine. Have you any idea as to why this is?

  12. #12
    AndyRob1973 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2020
    Posts
    81
    Hi again,

    I've scoured the net and found something that appears to work in the click event of 'Link'.

    I have no idea how it works, so if anyone could explain it or improve on it, I'd be grateful!

    Code:
    Private Sub Link_Click()
    
    Shell "explorer " & Chr(34) & Me.Link & Chr(34)
    
    End Sub

  13. #13
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Probably, is an Internet Explorer issue, but, as you found something that works -go ahead!

    You can use your favorite web browser with Shell. For example:
    Code:
    Shell "C:\Program Files\Mozilla Firefox\firefox.exe " & Chr(34) & Me.Link & Chr(34)
    Cheers,
    John

  14. #14
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    Check out the ShellExecute routine that I linked to in post#2 http://access.mvps.org/access/api/api0018.htm

    Its not only good for urls but works with emails, files, folders, URLs and if there is an unknown extension will open the "Open with" dialog.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Format Concatenated String
    By JimO in forum Access
    Replies: 3
    Last Post: 05-17-2016, 04:32 PM
  2. hyper link in vba email code
    By baronqueefington in forum Programming
    Replies: 2
    Last Post: 02-06-2015, 02:38 AM
  3. Export attach field and replac with hyper link
    By ahmadrezaahmad in forum Import/Export Data
    Replies: 1
    Last Post: 07-20-2013, 01:03 PM
  4. Replies: 1
    Last Post: 11-01-2012, 09:49 AM
  5. Hyper link from a Form and query
    By ajrourke in forum Programming
    Replies: 0
    Last Post: 05-09-2011, 12:59 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