Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create desktop shortcut for a MDB file by codes.

Status
Not open for further replies.

softlover

Programmer
Apr 4, 2002
88
CN
I want to create shortcut for a file and put it on the desktop. The codes need run under ACCESS2000.
 
try this
Code:
Set objShell = CreateObject("WScript.Shell")
strFolder = "C:\Documents and Settings\username\Desktop"
Set objShortCut = objShell.CreateShortcut(strFolder & _
 "\myaccess.lnk")
objShortCut.TargetPath = "C:\mypath\myaccess.mdb"
objShortCut.Description = "Open my access"
objShortCut.HotKey = "Ctrl+Shift+N"
objShortCut.Save
i know that the desktop is also a varable but i dont rembber what it is right now
 
I find a way which use "wscript.shell" and it can run well under WinME/2000/XP but failed under Windows98. Why?

Public Function CreateShortCut(ByVal Name As String, ByVal Description As String, TargetPath As String, WorkingDirectory As String)
Dim wsh As Object
Dim sf As Object
Dim Shortcut As Object
Set wsh = CreateObject("wscript.shell")
Set sf = wsh.SpecialFolders
Set Shortcut = wsh.CreateShortCut(sf("AllUsersDesktop") & "\" & Name & ".lnk")
Shortcut.TargetPath = TargetPath
Shortcut.Description = Description
Shortcut.WorkingDirectory = WorkingDirectory
Shortcut.Save
End Function

Private Sub CreateCut()
CreateShortCut "example_Muster", "", "C:\Muster.mdb", "C:\"
End Sub
 
The 9x way:
Set Shortcut = wsh.CreateShortCut(sf("Desktop") & "\" & Name & ".lnk")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Under windows98, The debugger gave the message "ACTIVEX can't create object" when run at the line below:
Set wsh = CreateObject("wscript.shell")
 
Sorry if I've missed the point here. I always a much simpler way which probably reflects my age!
Create a batch file using syntax you can find in Help (Startup command-line options & Set command-line options for starting Access) and then either put the batch file or a shortcut to it on the desktop.
That way you can decide which version of Access to use and code in different ways of opening the database. The disadvantage is that you need explicitly state paths, but for a single PC that's not normally a problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top