Create Shortcut

J

Jose Perdigao

I have the following cod to create shortcuts (This code I copied from this
newsgroup).

Public Sub CreateDesktopShortcut(strShortcutTitle As String, Optional
strTargetPath As String = "")
On Error Resume Next
Dim oShell As IWshShell_Class
Dim oShortcut As IWshShortcut_Class
Dim vItem As Variant
Dim vType As Variant
Set oShell = New IWshShell_Class
If strTargetPath = "" Then
strTargetPath = CurrentDb.Name
End If
For Each vItem In oShell.SpecialFolders
If Mid(vItem, Len(vItem) - 6, 7) = "Desktop" And InStr(1, vItem, "All
Users") = 0 And InStr(1, UCase(vItem), "ADMINISTRATOR") = 0 Then
oShortcut.Delete 'Delete existing shortcut
Set oShortcut = oShell.CreateShortcut(vItem & "\" & strShortcutTitle
& ".lnk")
oShortcut.IconLocation = PathFE() & "Icons\WorkOrder.ico, 0"
oShortcut.TargetPath = strTargetPath
oShortcut.Save
End If
Next
End Sub

This function works fine to create shortcut I we want using only the path of
the application, example ("C:\Program Files\Microsoft
Office\Office11\Samples\Northwind.mdb")

However, I have the following questions:
1. I would like add the command line with the path of MASccess, example:
"C:\Program Files\Microsoft Office\Office11\MSAccess.exe" "C:\Program
Files\Microsoft Office\Office11\Samples\Northwind.mdb"
I tried to add the path of MASaccess but I couldn't. The marks ("") doesn't
show in the target of the icon.

2. How can I get the path of MSAccess automatically?
Any suggestions?
Thanks a lot
José Perdigao
 
T

Terry Kreft

The following will produce a command line where the path to Access and the
currentdb.name are quote delimited. Note how the quotes within quotes are
doubled up each time.

strTargetPath = """" & SysCmd(acSysCmdAccessDir) & "msaccess.exe" _
& """ """ & CurrentDb.Name & """"

On my test produced
"D:\Program Files\Microsoft Office\OFFICE11\msaccess.exe" "C:\Documents and
Settings\mpstekre\My Documents\NGTest.mdb"
 
J

Jose Perdigao

Hi Terry,

I'm frustrated with this.

I run the function and the shortcut is created, the strTargetPath is
correct, my result is:

"C:\Program Files\Microsoft Office\OFFICE11\msaccess.exe"
"C:\Databases\DB_WorkOrder\WorksFRM.mde"



But it doesn't open. It appears a msg, Windows is searching the file
WorksFRM.mde.

I don't understand because the file is in the correct path.



If a put manually the path in shortcut properties START IN:
C:\Databases\DB_WorkOrder and then, it opens.

So, how can I add the path in START IN, in the shortcut with this function?



How can I replace the existing shortcut by new one? I mean, delete the
existing shortcut and create new one? I tried oShortcut.Delete but doesn't
work.



Any suggestions?

Thanks,

josé perdigão
 
D

Douglas J. Steele

Add a line

oShortcut.WorkingDirectory = "C:\Databases\DB_WorkOrder\"

However, I really wouldn't have though that it would be necessary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top