How can I make a Hyperlink Button (1 Viewer)

Steve C

Registered User.
Local time
Today, 15:30
Joined
Jun 4, 2012
Messages
120
May I ask, how can I make a Hyperlink Button on my Form?

Of course, my records have a Hyperlink Field.

Adding a Hyperlink Field to my Form works fine, but it doesn't look right. Instead I want a button without the http://www... text written in it.

I looked at the Hyperlink Field's "On Click" event but it seems empty (but works fine). The VBA code must be here somewhere!

Any pointers please gentlemen?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:30
Joined
Feb 19, 2002
Messages
43,427
Any control that offers a click event can function as a button so if you can't format an actual button to look the way you want, try formatting a text box.
 

Steve C

Registered User.
Local time
Today, 15:30
Joined
Jun 4, 2012
Messages
120
Thank you for your answer Pat, but my list of Format options for a Text Box is different to a Button - so I can't make it look even close!

How about a Button which fires the Hyperlink Field? Is that a daft idea? What might be the VBA for that?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:30
Joined
Feb 19, 2002
Messages
43,427
You can put any code you want into events. Look up the FollowHyperlink Method to see the code you need.
 

Steve C

Registered User.
Local time
Today, 15:30
Joined
Jun 4, 2012
Messages
120
Thank you Pat - I did exactly what you said - it works great!

Here's what I did if anyone is interested. TextBox1 contains a Hyperlink (that's unique to each Record). But, I want a Button instead of a Text Box - because it'll look nicer.

As Pat suggested, I looked up "FollowHyperlink Method" here;

http://msdn.microsoft.com/en-us/library/office/ff822080.aspx

Next I created a Button without a Wizard called Command0

In the OnClick event of Command0 I wrote this

Private Sub Command0_Click()
Dim WWWAddr As String
WWWAddr = [TextBox1]
Application.FollowHyperlink WWWAddr
End Sub

Next I set TextBox1 Properties to Visible NO. Now the button does the business. Happy days. Thank you Pat

Next I want Command0 to grey out if TextBox1 is empty.

This doesn't work in the Form OnCurrent - I am not sure what to try next

Private Sub Form_Current()
If Me.TextBox1 Is Null Then
Me.Command0.Enabled = False
Else
Me.Command0.Enabled = True
End If
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:30
Joined
Feb 19, 2002
Messages
43,427
If .Enabled is False AND .Locked is FALSE, the control should be Grey. If .Enabled is False AND .Locked is True, the control will not be Grey. It is also possible that the control contains a ZLS rather than null. Try this:
If Me.TextBox1 & "" = "" Then
This will handle either null or ZLS.
 

Steve C

Registered User.
Local time
Today, 15:30
Joined
Jun 4, 2012
Messages
120
Thank you Pat - you've done it again.

Here's what I did for the benefit of anyone following.

In the OnCurrent Event of Form0 I wrote

Private Sub Form_Current()
If Me.WWWAddr & "" = "" Then
Me.Command0.Enabled = False
Else
Me.Command0.Enabled = True
End If
End Sub

What happens now is; the button won't work - if there isn't an hyperlink to follow - which is better than the alternative.

I couldn't find a .Locked property for the Button (it's there for Text Boxes) - but it didn't matter because the Button greys out just fine.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:30
Joined
Feb 19, 2002
Messages
43,427
When I define my tables, I always set the AllowZLS property to No EXCEPT when I will be appending data to the table that comes from a mainframe. In general, I don't want to worry about always having to worry about ZLS in my query criteria. You can't avoid this when working with forms because depending on how a user "clears" a textbox, you end up with Null or ZLS. Since you can's see a ZLS, users think that just typing a space will "clear" a field but in fact, Access makes it a ZLS whereas if you select the contents and press the delete key, Access makes the value a null.
 

Users who are viewing this thread

Top Bottom