Link to home
Start Free TrialLog in
Avatar of paulmcneil
paulmcneilFlag for United States of America

asked on

The item this shortcut refers to has been changed or moved

I use the code below to create a desktop shortcut using WScript.shell. It creates the desktop icon successfully. When I double click the icon to log in to the database, I ge the message that it can;t find the mdw named in the TargetPath. This TargetPath string is exactly the same as the target path of the icon I created manually/ Why does it say it can;t find the mdw when it is in fact in the named folder? Am I doing something wrong with the properties when I create the icon?
Dim myWSH as object
Dim strAccessPath As String
Dim strShortcutTarget As String
 
Set myWSH = CreateObject("WScript.Shell")
strAccessPath = myWSH.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\Access\InstallRoot\Path")
strAccessPath = strAccessPath & "MSACCESS.EXE"
strShortcutTarget = Chr$(34) & strAccessPath & Chr$(34) & " " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdb" & Chr$(34) _
 & " /wrkgrp " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdw" & Chr$(34)
 
Set WSHShortcut = myWSH.CreateShortcut("C:\Documents and Settings\All Users\Desktop\Appeals Database.lnk")
With WSHShortcut
    .TargetPath = strShortcutTarget
    .IconLocation = strAccessPath & ",1"
    .WorkingDirectory = "C:\"
    .Save
End With
Set myWSH = Nothing
Set WSHShortcut = Nothing

Open in new window

Avatar of rockiroads
rockiroads
Flag of United States of America image

Im thinking  this might need to be broken down

strShortcutTarget should be strAccessPath

And I think there is another property you can set called Arguments

so

.Arguments = "C:\BWPhysicianOrg\BWPOBillingCoding.mdb /wrkgrp C:\BWPhysicianOrg\BWPOBillingCoding.mdw"


I'm just wondering why you need code to create a shortcut?
Avatar of paulmcneil

ASKER

I've isolated the problem. My shortcut string has the forward slash for the wrkgrp switch and that / keeps getting converted to a back slash by the TargetPath property even if a I use the ascii code for /, it still flips the / to \.
try escaping it

did it work using .Arguments ?
rockiroads,
What do you mean trying escaping it?
Escaping does not work
Put a \ before the /
like this   \/wrkgrp

eg

strShortcutTarget = Chr$(34) & strAccessPath & Chr$(34) & " " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdb" & Chr$(34) _
 & " \/wrkgrp " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdw" & Chr$(34)
yes your right, I just tried it
but using .arguments like I said earlier seems to do the trick. I just gave it a test

strShortcutTarget = Chr$(34) & strAccessPath & Chr$(34)
strArguments = Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdb" & Chr$(34) _
 & " /wrkgrp " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdw" & Chr$(34)
 
Set WSHShortcut = myWSH.CreateShortcut("C:\Documents and Settings\All Users\Desktop\Appeals Database.lnk")
With WSHShortcut
    .TargetPath = strShortcutTarget
    .Arguments = strArguments

rockiroads,

Now I'm using this test code and it doesn't create the shortcut at all.
Dim myWSH As Object
Dim wshshortcut As Object
Dim fs As Object
 
Set fs = CreateObject("Scripting.FileSystemObject")
 
If fs.FileExists("C:\Documents and Settings\All Users\Desktop\Appeals Database.lnk") = True Then
  fs.deletefile ("C:\Documents and Settings\All Users\Desktop\Appeals Database.lnk")
End If
 
Set myWSH = CreateObject("WScript.Shell")
 
strShortcutTarget = Chr$(34) & strAccessPath & Chr$(34)
strArguments = Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdb" & Chr$(34) _
 & " /wrkgrp " & Chr$(34) & "C:\BWPhysicianOrg\BWPOBillingCoding.mdw" & Chr$(34)
 
Set wshshortcut = myWSH.CreateShortcut("C:\Documents and Settings\All Users\Desktop\Appeals Database.lnk")
With wshshortcut
    .TargetPath = strShortcutTarget
    .Arguments = strArguments
End With

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
in the last code you posted, you had forgotten to add

.Save

also did you intentionally remove the stting of the icon and working directory?
thanks rockiroads I really appreciate it