Solved

Create Desktop Shortcut

Posted on 2006-11-17
4
328 Views
Last Modified: 2008-01-16
I would like to create a VBA module that will create a desktop shortcut that will launch my application: "C:\MyApp.mdb" , name the shortcut "My Application" and use the file "C:\MyApp.bmp" as the icon for the desktop shortcut. I have found the following module on another question on EE but cannot get it to work. Can anyone help me achieve what I need?

Private Sub Form_Load()
    '... do whatever you're doing already here

    Dim icon As String
    'Change "house.ico" to whatever your icon is... if you wanted you could
    'name the icon the same as the .mdb file and then just autoload it like this:
    'icon = Application.CurrentProject.FullName & ".ico"        'looks for c:\path\to\my.mdb.ico
    icon = Application.CurrentProject.Path & "\house.ico"
   
    Dim dbs As Database
    Set dbs = CurrentDb()

    On Error Resume Next
    If dbs.Properties("AppIcon") Is Nothing Then
        ' Create property if necessary.
        Dim prp As Property
        Set prp = dbs.CreateProperty("AppIcon", dbText, icon)
        dbs.Properties.Append prp
        Set prp = Nothing
    Else
        ' Property already exists, just save new value.
        dbs.Properties("AppIcon").Value = icon
    End If
   
    Application.RefreshTitleBar
    Application.RefreshDatabaseWindow
0
Comment
Question by:Rob4077
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
stevbe earned 500 total points
ID: 17964758

Public Function MakeShortcut()

  Dim scr As Object
  Dim scrLink As Object
  Dim strPath As String
  Set scr = CreateObject("WScript.Shell")

  strPath = scr.SpecialFolders("Desktop") & "\test.lnk"
 
  Set scrLink = scr.CreateShortcut(strPath)
 
  scrLink.TargetPath = "C:\MyApp.mdb"
  scrLink.IconLocation = "C:\MyApp.bmp"
  scrLink.Save

  Set scrLink = Nothing
  Set scr = Nothing

End Function

here is a great link:
http://www.windowsdevcenter.com/pub/a/windows/2004/04/13/VB_Shortcuts.html
0
 

Author Comment

by:Rob4077
ID: 17964972
That works BRILLIANTLY!!! Thanks.
0
 
LVL 39

Expert Comment

by:stevbe
ID: 17966275
Glad to hear it worked for you. If you are all set, please accept my post so we can close this one down and move on :-)

Steve
0
 

Author Comment

by:Rob4077
ID: 17974310
Sorry for the delay - forgot.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

743 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

10 Experts available now in Live!

Get 1:1 Help Now