Click an image to open a website

ECEK

Registered User.
Local time
Today, 22:52
Joined
Dec 19, 2012
Messages
717
Just a quickie.
I have inserted an image onto my form. What is best practice to get it to link to a website. i.e. the hover hand appears and on click it opens my browser to a pre-defined website.
 
In the image click event, use

Code:
 Application.FollowHyperlink "http://www.mywebsite.com"
 
You have an OnCLick event in the image control, use that. Assuming the picture is linked to the Primary key something like this would open the picture;
Code:
If Me.olePDFLink.Picture = sPath & Me.YourPrimaryKey & ".jpg" Then
        FollowHyperlink Me.olePDFLink.Picture
    End If
Where sPath is the path to the storage location and the picture is named after the primary key
 
put this in a module.

Code:
Private Const SW_HIDE = 0
Private Const SW_MINIMIZE = 6
Private Const SW_RESTORE = 9
Private Const SW_SHOW = 5
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOWNORMAL = 1

#If Win64 Then
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
( _
        ByVal hwnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long _
) As Long
#Else
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
( _
        ByVal hwnd As Long, _
        ByVal lpOperation As String, _
        ByVal lpFile As String, _
        ByVal lpParameters As String, _
        ByVal lpDirectory As String, _
        ByVal nShowCmd As Long _
) As Long
#End If

Public Sub ExecuteFile(sFileName As String, Optional sAction As String = "Open")
    Dim lngWindowMode As Long
    'sAction can be either "Open" or "Print".
    lngWindowMode = IIf(sAction = "Open", SW_SHOWNORMAL, SW_SHOWNA)
    If ShellExecute(Access.hWndAccessApp, sAction, _
        sFileName, vbNullString, "", lngWindowMode) < 33 Then
        DoCmd.Beep
        MsgBox "File not found."
    End If
End Sub

on the Click Event of your image, call the sub:

Code:
Private Sub Image0_Click()
ExecuteFile "web address to browse" 'put the website here inside the quote
End Sub
 
Thanks guys. I used Ridders' solution.
thanks
 
You're welcome but all 3 methods work and all have their merits
 

Users who are viewing this thread

Back
Top Bottom