Thursday, April 08, 2004

A Quick and Easy Way to create a Shortcut in MS Access:

Private Function fnMakeShellShortcut()
On Error GoTo Err_fnMakeShellShortcut

' Add a Reference to the Windows Script Host Object Model
' using Tools, References... to locate and register

Dim oShell As IWshShell_Class ' Shell object
Dim oShortcut As IWshShortcut_Class ' ShortCut object
Dim sDesktop As String ' Desktop Path
Dim sTargetPath As String ' Path to application .exe
Dim sQUOTE As String

sQUOTE = Chr(34)
Set oShell = New IWshShell_Class ' Create shell object

' Get Desktop path
sDesktop = oShell.SpecialFolders.Item("Desktop")

' Create shortcut on desktop
Set oShortcut = oShell.CreateShortcut(sDesktop & "\MyAcc2000DBase.lnk")

' Shortcut properties
sTargetPath = oShell.ExpandEnvironmentStrings("C:\Program Files\Microsoft Office 2000\Office")
With oShortcut
.TargetPath = sTargetPath & "\msaccess.exe"
.IconLocation = "C:\Program Files\Microsoft Office 2000\Office\msaccess.exe, 0"
.Arguments = sQUOTE & "C:\Program Files\My Database Folder\MyDatabase.mdb" & sQUOTE
.WorkingDirectory = sDesktop
.Description = "My Database"
End With

Exit Function

Select Case Err.Number
Case 0
Resume Next
Case Else
MsgBox Err.Number & ": " & Err.Description
End Select

Resume Exit_fnMakeShellShortcut

Resume 0 '*** For debugging purposes only
Exit Function

End Function

NSW MSDN article Microsoft Office Word 2003 XML: Memo Styles Sample, which examines some common XML-related tasks using the menus, task panes, and other parts of the user interface.

No comments: