none
How can I, using VBA, detect a Hyperlink data type within a Text Box control? RRS feed

  • Question

  • I have a client who wants all hyperlink data types to remain Enabled, even if the remainder of the form is in Read-Only mode.
    Monday, November 13, 2017 5:44 PM

All replies

  • Hi,

    I thought read-only forms don't affect the functionality of hyperlink fields? Are you saying nothing happens if the user clicks on the hyperlink? When you say "read-only," what exactly do you mean? Make sure the textbox is enabled to activate the link.

    But to answer your question, you can try looking into the HyperlinkPart function.

    Just my 2 cents...

    Monday, November 13, 2017 6:24 PM
  • Hi Daddy Warbucks Esq,

    I try to test the issue on my side.

    first I make the form read only and then try to click the link in the textbox.

    I find that it did not open the Hyperlink.

    testing example:

    Private Sub Form_Load()
    Me.Text5.Value = "https://www.microsoft.com"
    End Sub

    Output:

    you can see that nothing happens when I click on the link.

    so to solve the issue, I add the Textbox click event and use "Application.FollowHyperlink" method.

    example:

    Private Sub Form_Load()
    Me.Text5.Value = "https://www.microsoft.com"
    End Sub
    
    
    Private Sub Text5_Click()
    Application.FollowHyperlink Me.Text5
    End Sub
    

    Output:

    Reference:

    Application.FollowHyperlink Method (Access)

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 14, 2017 6:07 AM
    Moderator
  • Hmm, so how exactly do you set a form as "read-only?" I just gave it a try, and I was able to click on the Hyperlink Field without any problems. I didn't have to use any code.

    Here's what I did:

    I created the following table:

    and then added the following record to it:

    Then, I created the following form based on the above table:

    with the following Form Properties set:

    But when I clicked on the Textbox, my browser opened to the website as expected.

    What am I missing?

     
    Tuesday, November 14, 2017 4:26 PM
  • Rather than setting the form properties, in most cases I would do this on a control basis by firstly setting the Tag property of each bound control you wish to be read-only to LockMe.  Then in the form's Open event procedure lock and disable those controls with:

    Dim ctrl As Control

    For Each ctrl In Me.Controls
        If ctrl.Tag = "LockMe" Then
            ctrl.Locked = True
            ctrl.Enabled = False
        End If
    Next ctrl

    This has the advantageous of allowing unbound controls such as a navigation combo box to be still available, which would not be the case if the form's AllowEdits property were set to False.  By leaving the hyperlink's control untagged, this would be available to the user of course.

    Ken Sheridan, Stafford, England

    Tuesday, November 14, 2017 10:06 PM
  • Hi DBguy,

    I also make the form read only in a same way as you did.

    the difference was I was setting the value in Textbox using variable.

    I again made the test and store the URL in Hyperlink field.

    I can confirm that when I run the form and click the link it open in the browser without any issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 15, 2017 5:04 AM
    Moderator
  • Hi Deepak,

    So if this is correct, then I don't see how the OP is having any problems clicking on a hyperlink field. It must be in the way the form is set as "read-only;" because if it was set as we have demonstrated, then no VBA code is necessary.

    Ken, have you tried clicking on a Hyperlink field if the Textbox is Locked? Just curious...

    Wednesday, November 15, 2017 6:52 PM
  • Ken, have you tried clicking on a Hyperlink field if the Textbox is Locked? Just curious...

    I haven't, but I'll take it from you that it's possible.  The real point of my reply was to point out that a form can be made read-only as far as its bound controls only are concerned, without also disabling editable unbound controls.  The form's AllowEdits property is something of a blunt instrument in this respect, in that controls such as a navigational combo box are disabled, as well as the bound controls, if the AllowEdits property is False.

    Ken Sheridan, Stafford, England

    Wednesday, November 15, 2017 10:53 PM
  • Hi Ken,

    Thanks for the clarification. I guess we're all in the dark as far as how the OP managed to make the form "read-only." As you said, as long as the control is Enabled, it can be Locked, and the link "should" still work without needing for a code.

    Actually I also prefer using the Tag property to manage which Form Controls should be modified.

    Cheers!

    Thursday, November 16, 2017 5:52 AM
  • Hi,

    Sorry, I wasn't able to reply to this earlier.

    The Access Form doesn't have a "Read Only" property but the Controls can be disabled on the Form to make it appears as if the Form is "Read Only".

    With a disabled Control, the hyperlink doesn't work. Since you want to Enable the Hyperlink controls and the rest of the controls remains disable, here's what you can do. Use the Control's property of the Textbox called "IsHyperlink", set the Textbox to "Yes". I assumed you know this.

    Here a sample code on a OnOpen event of the Form you can try out.

    Private Sub Form_Open(Cancel As Integer)
    On Error Resume Next
    Dim ctl As Control
    With Me
    For Each ctl In Form.Controls
    If ctl.IsHyperlink = True Then
    ctl.Enabled = True
    End If
    Next
    End With
    End Sub
    

    Thursday, November 23, 2017 7:36 AM
  • Hi Daddy Warbucks Esq,

    I can see that after creating this thread, you did not done any follow up on this issue.

    is your issue is solved?

    if yes, I suggest you to post your solution and mark it as an answer.

    if your issue is still exist then try to refer the suggestions given by the community members.

    if you have any further questions then let us know about that.

    we will try to provide further suggestions to solve the issue.

    this thread is still open and will remain open until you mark the answer.

    so please try to update the status of the issue on this thread and take appropriate action to keep this forum healthy and helpful.

    Thanks for your understanding.

    Regards

    Deepak 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 24, 2017 12:57 AM
    Moderator