473,750 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to activate hyperlink in text box

24 New Member
Hello,

I have a problem with hyperlink.
I have a text box that contains link to the document. I enter the link by clicking on the button "add link". When I add link, the windows browser opens and i can search for exact document. But when I save the path in the Link text box, the link doent work. It is stored in News table and I changed it for hyperlink but still doesnt work. I noticed that when I am saving the path, it saves me the path as a link name that is shown in the text box, but the hyperlink path is empty.
How to make it works?
I would be grateful for help.


Greets

Greg
Nov 14 '07
15 37912
dillneus
24 New Member
The following code, placed in the Click() Event of a Command Button named cmdPopulateHype rlink will:
  1. Open a File Dialog Box, and allow you to select only 1 File of any type.
  2. Allow you to customize the Button and Dialog Title Captions within the File Dialog Box.
  3. Write the Hyperlink Caption and Address (both are required) to the Link Text Box on the Current Form. The Control Source for this Link Text Box is the [Link] Field.
  4. The Record Source for the Form is the Table News.
  5. The code has been thoroughly tested and is fully functional. I inserted Comments where I thought they may be needed.
  6. Any questions, feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPopulateHyperlink_Click()
  2. 'First, set a Reference to the Microsoft Office XX.X Object Library
  3.  
  4. Dim strButtonCaption As String, strDialogTitle As String
  5. Dim strHyperlinkFile As String
  6.  
  7. 'Define your own Captions if necessary
  8. strButtonCaption = "Save Hyperlink"
  9. strDialogTitle = "Select File to Create Hyperlink to"
  10.  
  11. With Application.FileDialog(msoFileDialogFilePicker)
  12.   With .Filters
  13.     .Clear
  14.     .Add "All Files", "*.*"     'Allow ALL File types
  15.   End With
  16.   'The Show Method returns True if 1 or more files are selected
  17.     .AllowMultiSelect = False       'Critical Line
  18.     .FilterIndex = 1 'Database files
  19.     .ButtonName = strButtonCaption
  20.     .InitialFileName = vbNullString
  21.     .InitialView = msoFileDialogViewDetails     'Detailed View
  22.     .Title = strDialogTitle
  23.   If .Show Then
  24.     For Each varItem In .SelectedItems 'There will only be 1
  25.       'Caption and Address of Hyperlink will be the same (Caption#Address)
  26.       strHyperlinkFile = varItem & "#" & varItem
  27.         Me![Link] = strHyperlinkFile
  28.     Next varItem
  29.   End If
  30. End With
  31. End Sub
  32.  

Thank you very much for help. Now it is more clear for me how it works.
However i have a problem while clicking the button:
Compile error: Method or data member not found.

I pasted that code in VB in On click option. My button name is cmdPopulateHype rlink. And the other decribed option are the same. So i dont know what to do to work it out.
I also put references for Microsoft Office 12.0 Object Library
I dont know if its tell you sth but all the time i click button it shows me that error and then in the line : With Application.Fil eDialog(msoFile DialogFilePicke r), the work FileDialog is selected (not in yellow like in the beggining but in blue, like selecting for copying). I know that maybe its sth simple and i have really stupid remark, but as i said in the beggining, this is my beggining with VB...

greets
Greg
Nov 19 '07 #11
ADezii
8,834 Recognized Expert Expert
Thank you very much for help. Now it is more clear for me how it works.
However i have a problem while clicking the button:
Compile error: Method or data member not found.

I pasted that code in VB in On click option. My button name is cmdPopulateHype rlink. And the other decribed option are the same. So i dont know what to do to work it out.
I also put references for Microsoft Office 12.0 Object Library
I dont know if its tell you sth but all the time i click button it shows me that error and then in the line : With Application.Fil eDialog(msoFile DialogFilePicke r), the work FileDialog is selected (not in yellow like in the beggining but in blue, like selecting for copying). I know that maybe its sth simple and i have really stupid remark, but as i said in the beggining, this is my beggining with VB...

greets
Greg
Just for verification, what Version of Access are you using?
Nov 19 '07 #12
dillneus
24 New Member
Just for verification, what Version of Access are you using?
I am using: MS Access 2000
Nov 19 '07 #13
dillneus
24 New Member
I am using: MS Access 2000
If it helps, before i was using module code for file browser like this (but it saved me only display text, not hyperlink):
Expand|Select|Wrap|Line Numbers
  1. '.=========================================================================
  2. '.Browse Files Module
  3. '.Copyright 1999 Tribble Software.  All rights reserved.
  4. '.Phone        : (616) 455-2055
  5. '.E-mail       : carltribble@earthlink.net
  6. '.=========================================================================
  7. ' DO NOT DELETE THE COMMENTS ABOVE.  All other comments in this module
  8. ' may be deleted from production code, but lines above must remain.
  9. '--------------------------------------------------------------------------
  10. '.Description  : This module calls directly into comdlg32.dll to allow user
  11. '.               to select a filename using the Windows Common Dialog.  The
  12. '.               user may browse for a file, or enter a file name directly.
  13. '.Written By   : Carl Tribble
  14. '.Date Created : 04/05/1999 09:56:31 AM
  15. '.Rev. History :
  16. ' Comments     : Normally, to use the Common Dialog you need to physically
  17. '                place the ActiveX control onto a form and then use code
  18. '                behind the form to implement its functionality.  This
  19. '                module allows you to incorporate the functionality of the
  20. '                File Open/Save part of the Common Dialog without the
  21. '                ActiveX control itself. This module is completely self-
  22. '                contained.  Simply copy it into your database to use it.
  23. '.-------------------------------------------------------------------------
  24. '.
  25. ' ADDITIONAL NOTES:
  26. '
  27. '  This module only provides the Open/Save file dialog, not the other
  28. '  CommonDialog interfaces (ColorChooser, Help, PrintDialog, etc.)
  29. '
  30. '  If you want your user to browse for folder names (paths) you must use
  31. '  the module basBrowseFolders instead.
  32. '
  33. '  TO STREAMLINE this module for production programs, you should remove:
  34. '     1) Unnecessary comments
  35. '     2) Flag Constants which you do not intend to use.
  36. '     3) The test procedure tsGetFileFromUserTest
  37. '
  38. '--------------------------------------------------------------------------
  39. '
  40. ' INSTRUCTIONS:
  41. '
  42. '         ( For a working example, open the Debug window  )
  43. '         ( and enter tsGetFileFromUserTest.              )
  44. '
  45. '.All the arguments for the function are optional.  You may call it with no
  46. '.arguments whatsoever and simply assign its return value to a variable of
  47. '.the Variant type.  For example:
  48. '.
  49. '.   varFileName = tsGetFileFromUser()
  50. '.
  51. '.The function will return:
  52. '.   the full path and filename selected or entered by the user, or
  53. '.   Null if an error occurs or if the user presses Cancel.
  54. '.
  55. '.Optional arguments may include any of the following:
  56. '. rlngFlags      : one or more of the tscFN* constants (declared below)
  57. '.                  Combine multiple constants like this:
  58. '.                   tscFNHideReadOnly Or tscFNFileMustExist
  59. '. strInitialDir : the directory to display when dialog opens
  60. '. strFilter     : a string containing any filters you want to use. Each
  61. '.                 part must be separated by the vbNullChar. -example below
  62. '. lngFilterIndex: a 1-based index indicating which filter to start with.
  63. '. strDefaultExt : Extension to use if user does not enter one.
  64. '. strFileName   : Default File to display in the File Name text box.
  65. '. strDialogTitle: Caption to display in the dialog's title bar.
  66. '. fOpenFile     : Boolean-True for the Open dialog, False for Save dialog.
  67. '
  68. ' FILTER EXAMPLE: The filter must be a string containing two parts for each
  69. '  filter.  The first part is the Description, it is what the user will see
  70. '  in the Files of Type box, e.g. "Text Files (*.txt)".  The second part is
  71. '  the actual filter, e.g. "*.txt".  Each part and each filter must be
  72. '  separated by the vbNullChar.  For example, to provide two filters, one for
  73. '  *.mdb files, and one for all files, use a statement like this:
  74. '
  75. '  strFilter = "Access (*.mdb)" & vbNullChar & "*.mdb" _
  76. '   & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
  77. '
  78. '  Then pass your strFilter variable as the strFilter argument for the call
  79. '  to tsGetFileFromUser()
  80. '
  81. '.--------------------------------------------------------------------------
  82. '.
  83.  
  84. Private Declare Function ts_apiGetOpenFileName Lib "comdlg32.dll" _
  85.  Alias "GetOpenFileNameA" (tsFN As tsFileName) As Boolean
  86.  
  87. Private Declare Function ts_apiGetSaveFileName Lib "comdlg32.dll" _
  88.  Alias "GetSaveFileNameA" (tsFN As tsFileName) As Boolean
  89.  
  90. Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
  91.  
  92. Private Type tsFileName
  93.    lStructSize As Long
  94.    hwndOwner As Long
  95.    hInstance As Long
  96.    strFilter As String
  97.    strCustomFilter As String
  98.    nMaxCustFilter As Long
  99.    nFilterIndex As Long
  100.    strFile As String
  101.    nMaxFile As Long
  102.    strFileTitle As String
  103.    nMaxFileTitle As Long
  104.    strInitialDir As String
  105.    strTitle As String
  106.    Flags As Long
  107.    nFileOffset As Integer
  108.    nFileExtension As Integer
  109.    strDefExt As String
  110.    lCustData As Long
  111.    lpfnHook As Long
  112.    lpTemplateName As String
  113. End Type
  114.  
  115. ' Flag Constants
  116. Public Const tscFNAllowMultiSelect = &H200
  117. Public Const tscFNCreatePrompt = &H2000
  118. Public Const tscFNExplorer = &H80000
  119. Public Const tscFNExtensionDifferent = &H400
  120. Public Const tscFNFileMustExist = &H1000
  121. Public Const tscFNPathMustExist = &H800
  122. Public Const tscFNNoValidate = &H100
  123. Public Const tscFNHelpButton = &H10
  124. Public Const tscFNHideReadOnly = &H4
  125. Public Const tscFNLongNames = &H200000
  126. Public Const tscFNNoLongNames = &H40000
  127. Public Const tscFNNoChangeDir = &H8
  128. Public Const tscFNReadOnly = &H1
  129. Public Const tscFNOverwritePrompt = &H2
  130. Public Const tscFNShareAware = &H4000
  131. Public Const tscFNNoReadOnlyReturn = &H8000
  132. Public Const tscFNNoDereferenceLinks = &H100000
  133.  
  134. Public Function tsGetFileFromUser( _
  135.  Optional ByRef rlngflags As Long = 0&, _
  136.  Optional ByVal strInitialDir As String = "", _
  137.  Optional ByVal strFilter As String = "All Files (*.*)" & vbNullChar & "*.*", _
  138.  Optional ByVal lngFilterIndex As Long = 1, _
  139.  Optional ByVal strDefaultExt As String = "", _
  140.  Optional ByVal strFileName As String = "", _
  141.  Optional ByVal strDialogTitle As String = "", _
  142.  Optional ByVal fOpenFile As Boolean = True) As Variant
  143.  
  144.    On Error GoTo tsGetFileFromUser_Err
  145.    Dim tsFN As tsFileName
  146.    Dim strFileTitle As String
  147.    Dim fResult As Boolean
  148.  
  149.    ' Allocate string space for the returned strings.
  150.    strFileName = Left(strFileName & String(256, 0), 256)
  151.    strFileTitle = String(256, 0)
  152.  
  153.    ' Set up the data structure before you call the function
  154.    With tsFN
  155.       .lStructSize = Len(tsFN)
  156.       .hwndOwner = Application.hWndAccessApp
  157.       .strFilter = strFilter
  158.       .nFilterIndex = lngFilterIndex
  159.       .strFile = strFileName
  160.       .nMaxFile = Len(strFileName)
  161.       .strFileTitle = strFileTitle
  162.       .nMaxFileTitle = Len(strFileTitle)
  163.       .strTitle = strDialogTitle
  164.       .Flags = rlngflags
  165.       .strDefExt = strDefaultExt
  166.       .strInitialDir = strInitialDir
  167.       .hInstance = 0
  168.       .strCustomFilter = String(255, 0)
  169.       .nMaxCustFilter = 255
  170.       .lpfnHook = 0
  171.    End With
  172.  
  173.    ' Call the function in the windows API
  174.    If fOpenFile Then
  175.       fResult = ts_apiGetOpenFileName(tsFN)
  176.    Else
  177.       fResult = ts_apiGetSaveFileName(tsFN)
  178.    End If
  179.  
  180.    ' If the function call was successful, return the FileName chosen
  181.    ' by the user.  Otherwise return null.  Note, the CancelError property
  182.    ' used by the ActiveX Common Dialog control is not needed.  If the
  183.    ' user presses Cancel, this function will return Null.
  184.    If fResult Then
  185.       rlngflags = tsFN.Flags
  186.       tsGetFileFromUser = tsTrimNull(tsFN.strFile)
  187.    Else
  188.       tsGetFileFromUser = Null
  189.    End If
  190.  
  191. tsGetFileFromUser_End:
  192.    On Error GoTo 0
  193.    Exit Function
  194.  
  195. tsGetFileFromUser_Err:
  196.    Beep
  197.    MsgBox Err.Description, , "Error: " & Err.Number _
  198.     & " in function basBrowseFiles.tsGetFileFromUser"
  199.    Resume tsGetFileFromUser_End
  200.  
  201. End Function
  202.  
  203. ' Trim Nulls from a string returned by an API call.
  204.  
  205. Private Function tsTrimNull(ByVal strItem As String) As String
  206.  
  207.    On Error GoTo tsTrimNull_Err
  208.    Dim I As Integer
  209.  
  210.    I = InStr(strItem, vbNullChar)
  211.    If I > 0 Then
  212.        tsTrimNull = Left(strItem, I - 1)
  213.    Else
  214.        tsTrimNull = strItem
  215.    End If
  216.  
  217. tsTrimNull_End:
  218.    On Error GoTo 0
  219.    Exit Function
  220.  
  221. tsTrimNull_Err:
  222.    Beep
  223.    MsgBox Err.Description, , "Error: " & Err.Number _
  224.     & " in function basBrowseFiles.tsTrimNull"
  225.    Resume tsTrimNull_End
  226.  
  227. End Function
Nov 19 '07 #14
dillneus
24 New Member
Everything is ok now.
Inspired by your code, i have simply copied "#" & into following line:

Me![Link] = "#" & varFileName

and now its working :)

it was so easy solution that now i am embaressed by posting that question :)

Thx very much for help and inspiration :)


Greg
Nov 19 '07 #15
ADezii
8,834 Recognized Expert Expert
Everything is ok now.
Inspired by your code, i have simply copied "#" & into following line:

Me![Link] = "#" & varFileName

and now its working :)

it was so easy solution that now i am embaressed by posting that question :)

Thx very much for help and inspiration :)


Greg
You are quite welcome. Many Users are confused when it comes to programmaticall y adding Hyperlinks to a Form Field Bound to a HyperLink Data Type. As a matter of fact, this will probably be the Subject of the next Tip of the Week.
Nov 19 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

4
7465
by: Tero Partanen | last post by:
Hello! I'm writing about a rather peculiar problem I'm having with Access2000. I have a table in which I have created one hyperlink-type field. I have given the field a default value which is an email-address. The default value is (for example): "mailto:mymail@here.com". Access2000 correctly inserts that information into the field everytime
9
15021
by: Paul | last post by:
Hi I have a data grid with a hyperlink column. the colum has numbers like 00001,000002, ect. Just wondering how to get the text value of the cell as tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text returns a blank string. It seems to work ok for the other columns that are just regular datagrid columns, not hyperlink types. Thanks. -- Paul G Software engineer.
19
3558
by: Joe | last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first column contains hyperlinks. When a user clicks one of these hyperlinks, he will navigate to another aspx page (referred to here as page_2). I need to cache the value of the link's text (hyperlink.text property) so that I can use it in the page_load event of page_2. I've thought of using a hidden field and then calling Request.Form("hdnClickedLinkText") in the...
2
2101
by: Keith Wilby | last post by:
I have a personnel database with a hyperlink field which contains the path to a mugshot. I was thinking of combining the hyperlink field with the surname field by putting the surname in the "Display Text" of the hyperlink. I have 200 or so existing records - can this be done either with code or in a query? I'm not sure of the syntax to use to reference the "Display Text" property (if it can be done at all). Many thanks. Keith.
20
3002
by: tshad | last post by:
I had posted this problem earlier and just noticed that the Hyperlink is the problem. Apparently, it doesn't figure out the path correctly. It uses the path of the file it is in, even if it is a control. I have 2 files "displayCompanyJobs.aspx" and "displayCompanyOverview.aspx" which are in both the folder "/jobseeker/" and "/employer/". I have a user control "displayCompanyJobs.ascx" that is in my /applicant/
13
42979
ADezii
by: ADezii | last post by:
Recently, there have been several questions and much confusion concerning the Topic of Hyperlinks. Specifically, Users wanted to know how to retrieve a File Name from a FileDialog Box, copy the Name to a Bound Text Box on a Form, and save the Hyperlink to the underlying Table. The code demos below will do just that: retrieve the Absolute Path of of File from a FileDialog Box, use the Base Name (no extension) as the Display Text for the...
1
2287
by: k lee | last post by:
I want to create a linkButton to activate my hyperlink which will open a new page in a new window. I would like to know how to code the code of activate the hyperlink which I wish to place it in the 'onclick' event of the linkButton.
1
2014
by: suvaline | last post by:
I dont know much about VBA, but maybe somebody can help me ;) I have this kind of SUB .. Sub kama2() Worksheets("kama").Activate Range("A51").Select Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True Application.WindowState = xlNormal Start_Timer End Sub ... and question ...
10
3006
by: sierra7 | last post by:
I'm trying to create a form where a user enters a document reference number and then clicks a command button to add a hyperlink to the document, via a file picker. Thanks to Adezii's excellent article http://bytes.com/topic/access/answers/725778-inserting-hyperlink-into-table I can manage to create a hyperlink to the document and store it in the table, but it is the full hyperlink path not the reference number of the document that is...
0
8999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9338
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4712
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.