Solved

The item this shortcut refers to has been changed or moved

Posted on 2009-03-30
13
2,507 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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