Hyperlink in label control RRS feed

  • Question

  • I am trying to use a label control as essentially a command button on a form but I would like it to behave as though it were a hyperlink.  I would like it to appear as a hyperlink, have the mouse pointer appear as the "finger pointer" on mouse over, display a small popup that says "click for more information" on mouse over, and display a message box when clicked.  Is there a  simple way to do this using the native hyperlink properties and perhaps simple error trapping, i.e., without writing a bunch of code?  What I have attempted thus far is simply to set the HyperlinkSubaddress property to "Click for more information" and added a MsgBox to the OnClick event.  This works great but the form/label control then attempts to actually follow the hyperlink "Click for more information" which of course does not exist and throws an error.  Is there any way to trap for this error so it is not displayed to the end user?  I don't want to write a bunch of code to simulate a hyperlink here.  Thanks.


    Friday, July 10, 2020 3:04 PM

All replies

  • I am trying to use a label control as essentially a command button on a form but I would like it to behave as though it were a hyperlink.

    Hi Bruce,

    What if you use a Textbox control instead of a Label control, and have it appear as a Label in the Open (or Load) event of the form?


    Friday, July 10, 2020 5:10 PM
  • I'd recommend using a text box formatted to look like a hyperlink.  For an illustration of how to then make it behave as a hyperlink take a look at BrowseDemo.zip in my public databases folder at:


    If you don't want the Open button to show just set its Visible property to False.  You will then have to change the code in the first text box's Click event procedure to move focus to another control rather than the Open button.  You'd also set the text box's BackStyle and BorderStyle properties to Transparent to make it look like a label.

    Ken Sheridan, Stafford, England

    • Edited by Ken Sheridan Friday, July 10, 2020 5:48 PM Hyperlink added.
    Friday, July 10, 2020 5:47 PM
  • I see that using a textbox has its advantages, i.e. that one can set the IsHyperlink property which a label control doesn't have.  This then allows you to format the contents as a hyperlink but without address or target set it doesn't try to treat the contents as an actual hyperlink except for the formatting.

    Unfortunately a textbox is a control that assumes focus once it is clicked.  I tried getting around this by setting Enabled to false and Locked to true but this disables its hyperlinked functionality as well as its click event.  And there is not a good way to display the "click for more information" popup that I need on mouseover as I could do with a true hyperlink.

    What I have discovered is that the error thrown by a label control with a bad hyperlink address is 7971 which can be trapped in the form error event:

        Select Case DataErr
            Case 7971
                Response = acDataErrContinue
            Case Else
                Response = acDataErrDisplay
        End Select

    So I can set up a label control as a hyperlink which meets all of my requirements as:

    lbl.Caption = "Printing disabled."
    lbl.HyperlinkSubAddress = "Click for more information"

    and I can put whatever code I need in its OnClick event.

    Thanks Imb-Hb and Ken for the suggestions and demo though. I learned some things I did not know about hyperlink properties today.


    Friday, July 10, 2020 6:28 PM
  • Unfortunately a textbox is a control that assumes focus once it is clicked.

    Hi Bruce,

    Good to hear you found a solution for your problem.

    If you don't want that a certain control gets the focus after it is clicked, you can use:    Me.PreviousControl.SetFocus  (Edit: in the Click event)

    I use this when a TextBox control has the focus, and you then click a command button: I want the TextBox keeps the focus.


    • Edited by Imb-hb Friday, July 10, 2020 7:09 PM Edit
    Friday, July 10, 2020 7:05 PM