I spoke too soon!
The routine (see below) does indeed create a shortcut with the proper
synthax. But when I try to launch it, it does not work and I get a Missing
Shortcut dialog asking me to locate the file.....
Yet, If I open the shortcut properties, cut the argument from the end, apply
the change then paste back the argument and close the shortcut and launch it
it works. What the?!?!
Function CreateDesktopShortcut() As Boolean
On Error GoTo Error_Handler
'Special folder location where the shortcut will be created
Const szlocation As String = "Startup"
'Extension that will be used for the shortcut file
Const szLinkExt As String = ".lnk"
Dim oWsh As Object 'WScript object
Dim oShortcut As Object 'Shortcut object
Dim szDb As String 'Path\Name.Ext of the current database
Dim szShortcutPath As String 'Path where to create the shortcut
Dim szShortcutName As String 'Name to be given to the shortcut
Dim szShortcut As String
Dim szTarget As String
' Initialize our variables
szDb = Application.CurrentDb.name
szShortcutName = "ReminderDb"
Set oWsh = CreateObject("WScript.Shell")
szShortcutPath = oWsh.SpecialFolders(szlocation)
' Create the shortcut path/filename
szShortcut = szShortcutPath & "\" & szShortcutName & szLinkExt
' Create the Shortcut target
' For my purposes I need to include the exe to run the db
szTarget = GetFileExecutable(Application.CurrentProject.name, _
Application.CurrentProject.Path) & Chr(34) & " "
szTarget = szTarget & Chr(34) & szDb
' Create the Shortcut file
Set oShortcut = oWsh.CreateShortCut(szShortcut)
' Populate the Shortcut properties
With oShortcut
.TargetPath = szTarget
' .IconLocation = szPath & szIconName
' .WorkingDirectory = WorkPath
' .WindowStyle = Window_Style
.Arguments = " /cmd = 'checkrem'"
'/cmd = "checkrem"
' .Hotkey
.Description = "Database date check routine"
' .IconLocation = TargetPath & "," & IconNum
.Save
End With
' Cleanup our object variables
Set oShortcut = Nothing
Set oWsh = Nothing
' if I've made it to here, everything is fine.
CreateDesktopShortcut = True
If Err.Number = 0 Then Exit Function
Error_Handler:
CreateDesktopShortcut = False
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: CreateDesktopShortcut" & vbCrLf &
"Error Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Exit Function
End Function
If you see something in my code that is blazingly wrong or explains this
weird behavior, please let me know.
So close, but so far!
QB