Is a button for a desktop shortcut possible?

Diana van den Berg
4StarLounger
Posts: 582
Joined: 06 May 2012, 20:05

Is a button for a desktop shortcut possible?

Post by Diana van den Berg »

1. Is it possible to create a button in a database that will create a shortcut on the desktop?
2. If so, is it possible to have the icon of that shortcut default to a particular icon?
3. If so, is it possible to have the name of that shortcut on the desktop default to particular text?

Thank you in anticipation.

User avatar
HansV
Administrator
Posts: 78448
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Is a button for a desktop shortcut possible?

Post by HansV »

Like this:

Code: Select all

Private Sub cmdCreateShortcut_Click()
    Dim objWSH As Object
    Dim objShortcut As Object
    Dim strDeskTop As String

    Set objWSH = CreateObject("WScript.Shell")
    strDeskTop = objWSH.SpecialFolders("Desktop")

    Set objShortcut = objWSH.CreateShortCut(strDeskTop & "\" & "MyShortcut" & ".lnk")
    With objShortcut
        .TargetPath = CurrentDb.Name
        .IconLocation = "C:\Program Files\Internet Explorer\Images\Bing.ico"
        .Save
    End With
    Set objWSH = Nothing
End Sub
This will create a desktop shortcut to the database from which the code is run. Change the path and name of the icon file to be used.
Best wishes,
Hans

Diana van den Berg
4StarLounger
Posts: 582
Joined: 06 May 2012, 20:05

Re: Is a button for a desktop shortcut possible?

Post by Diana van den Berg »

Yeee haaa! Lovely, Hans! Just what I wanted. Initially I didn't change "MyShortcut" to what I wanted, but have now and it is perrrrrrrrrfect!

Thank you! :chocciebar: