Solved

Make a text field on a form a hyperlink if a checkbox is true

Posted on 2014-11-17
4
182 Views
Last Modified: 2014-11-17
I'm trying to make a text box value a hyperlink if a checkbox is true.  Here is my code which isn't working...

    If Me.chkbxHyperlink = True Then
        Me.txtName.Hyperlink = True
    End If

    If Me.chkbxHyperlink = False Then
        Me.txtName.Hyperlink = False
    End If

Open in new window

0
Comment
Question by:SteveL13
  • 2
  • 2
4 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40447256
Nah, you don't want to do that.  The underlying data field must be either text or hyperlink, cannot be both, and you really don't want to make it a hyperlink.

What I would recommend is that you include a button to the right of the field, and if the checkbox is checked, enable that button, then use the Application.FollowHyperlink method to follow the hyperlink to the URL or file or email or whatever is associated with the txtName field.

An alternative would be to used the textboxes double click event and if the checkbox is clicked, then use the Application.Followhyperlink method.  Generally the same as above but with a double click on the textbox rather than using a command button.
0
 

Author Comment

by:SteveL13
ID: 40447723
Ok.  I have the checkbox named chkbxHyperlink.  And I have this code in the form:

Function GetHyperlink() As Boolean
    Dim strInput As String
 
    On Error GoTo Error_GetHyperlink
    strInput = Me.txtAwards
    Application.FollowHyperlink strInput, , True
    GetHyperlink = True
 
Exit_GetHyperlink:
    Exit Function
 
Error_GetHyperlink:
    MsgBox Err & ": " & Err.Description
    GetHyperlink = False
    Resume Exit_GetHyperlink
End Function

Open in new window


And I have a command button named cmdGoToHyperlink.  And for the onclck event of the command button I have this code:

    Call GetHyperlink

Open in new window


But it is not taking me to the web address specified in a field named txtHyperLink

I'm sure I don't have any of this right.
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40447762
you are referring to the txtAwards control in your GetHyperlink function, not to txtHyperlink.  Start out with that.

Personally, I think I would simpl do:

Private Sub cmdGoToHyperlink_Click

    if Me.chkbxHyperlink Then Application.Followhyperlink me.txtHyperlink, , True

End Sub

Open in new window

0
 

Author Closing Comment

by:SteveL13
ID: 40447822
That'll do it.  Worked!  Thanks.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question