Open a hyperlink on button click with vb code

F

Frank

Hi,

I'm looking for an example where in MS-Access a button opens de
default webbrowser and goes to the webpage I specified in the vba
code.

Something like this:

Private sub button_click()
dim strPage
strPage = "default.htm"
Open.hyperlink ("http://www.myurl.com/" & strPage)
end sub

Thanx, Frank
 
M

Marvin

Frank,

Maybe this will help (it uses a form - you can replace the textboxes with
your code):

Private Sub cmdFollowLink_Click()
If IsNull(Me.txtSubAddress) Then
Me.txtSubAddress = ""
End If
CreateHyperlink Me!cmdFollowLink, Me!txtSubAddress, _
Me!txtAddress ' Make sure the address is prefixed properly, e.g.
http://
End Sub


Sub CreateHyperlink(ctlSelected As Control, _
strSubAddress As String, Optional strAddress As String)
Dim hlk As Hyperlink
Select Case ctlSelected.ControlType
Case acLabel, acImage, acCommandButton
Set hlk = ctlSelected.Hyperlink
With hlk
If Not IsMissing(strAddress) Then
.Address = strAddress
Else
.Address = ""
End If
.SubAddress = strSubAddress
hlk.Follow
.Address = ""
.SubAddress = ""
End With
Case Else
MsgBox "The control '" & ctlSelected.Name _
& "' does not support hyperlinks."
End Select
End Sub

Good luck,

Marvin
 
M

Marvin

Frank,

Maybe this will help (it uses a form - you can replace the textboxes with
your code):

Private Sub cmdFollowLink_Click()
If IsNull(Me.txtSubAddress) Then
Me.txtSubAddress = ""
End If
CreateHyperlink Me!cmdFollowLink, Me!txtSubAddress, _
Me!txtAddress ' Make sure the address is prefixed properly, e.g.
http://
End Sub


Sub CreateHyperlink(ctlSelected As Control, _
strSubAddress As String, Optional strAddress As String)
Dim hlk As Hyperlink
Select Case ctlSelected.ControlType
Case acLabel, acImage, acCommandButton
Set hlk = ctlSelected.Hyperlink
With hlk
If Not IsMissing(strAddress) Then
.Address = strAddress
Else
.Address = ""
End If
.SubAddress = strSubAddress
hlk.Follow
.Address = ""
.SubAddress = ""
End With
Case Else
MsgBox "The control '" & ctlSelected.Name _
& "' does not support hyperlinks."
End Select
End Sub

Good luck,

Marvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top