Solved

The item this shortcut refers to has been changed or moved

Posted on 2009-03-30
13
2,469 Views
Last Modified: 2013-11-27
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

0
Comment
Question by:paulmcneil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
13 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24019457
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"


0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24019722
I'm just wondering why you need code to create a shortcut?
0
 

Author Comment

by:paulmcneil
ID: 24019914
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 \.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 65

Expert Comment

by:rockiroads
ID: 24019946
try escaping it

did it work using .Arguments ?
0
 

Author Comment

by:paulmcneil
ID: 24020300
rockiroads,
What do you mean trying escaping it?
0
 

Author Comment

by:paulmcneil
ID: 24020349
Escaping does not work
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24020360
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)
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24020376
yes your right, I just tried it
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24020403
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

0
 

Author Comment

by:paulmcneil
ID: 24020566
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

0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 24020626
I took your original code that you posted and added just strArguments

Dim myWSH As Object
Dim strAccessPath As String
Dim strShortcutTarget As String
Dim WSHShortcut
Dim strArguments 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)
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
    .IconLocation = strAccessPath & ",1"
    .WorkingDirectory = "C:\"
    .Save
End With
Set myWSH = Nothing
Set WSHShortcut = Nothing


And it created a shortcut (I deleted it first) with a target path of

"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "C:\BWPhysicianOrg\BWPOBillingCoding.mdb" /wrkgrp "C:\BWPhysicianOrg\BWPOBillingCoding.mdw"

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24020637
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?
0
 

Author Closing Comment

by:paulmcneil
ID: 31564330
thanks rockiroads I really appreciate it
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question