Solved

The item this shortcut refers to has been changed or moved

Posted on 2009-03-30
13
2,392 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
  • 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
 
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now