Solved

create a hyperlink in vb6

Posted on 2004-08-31
5
1,131 Views
Last Modified: 2012-06-27
how can i create a hyperlink in vb6?

such as a button that will send an email to a set email address

thanks
0
Comment
Question by:rinkydink
5 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11949171
Option Explicit

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

Private Const SW_SHOWNORMAL = 1

Private Sub Command1_Click()
    ShellExecute Me.hwnd, vbNullString, "mailto:someOne@someIsp.net", _
        vbNullString, "C:\", SW_SHOWNORMAL
End Sub
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 11949660
You can use ShellExecute to create a hyperlink, for eg. write the URL on a label and underline it to depict a hyperlink on the Click event of the Label use

Call ShellExecute( Me.hwnd, vbNullString, "http://google.com", vbNullString, "C:\", 1)

You need to declare the ShellExecute API at module/form level

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

if you give mailto:xxx in the URL it will open the default mail client for composing the mail and the user will have to send it.

0
 
LVL 2

Accepted Solution

by:
craigewens earned 100 total points
ID: 11950170
Create a label, and name it lblURL, and set its caption property to the internet address you want. If the URL is an email address, then un-comment one of the 'Call ShellExecute' lines, and comment out the line below that.

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
Private Sub lblURL_DragDrop(Source As Control, X As Single, Y As Single)
    If Source Is lblUrl Then
        With lblUrl
            .Font.Underline = False
            .ForeColor = vbBlack
            ' Call ShellExecute(0&, vbNullString, "Mailto:" & .Caption, vbNullString, vbNullString, vbNormalFocus)
            Call ShellExecute(0&, vbNullString, .Caption, vbNullString, vbNullString, vbNormalFocus)
        End With
    End If
End Sub

Private Sub lblURL_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    If State = vbLeave Then
        With lblUrl
            .Drag vbEndDrag
            .Font.Underline = False
            .ForeColor = vbBlack
        End With
    End If
End Sub

Private Sub lblURL_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    With lblUrl
        .ForeColor = vbBlue
        .Font.Underline = True
        .Drag vbBeginDrag
    End With
End Sub
0
 
LVL 76

Expert Comment

by:David Lee
ID: 11950637
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now